         return cell
     }
     
-    
     // When cell tapped, change to test
     func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
-        
         let source = searchDecks ?? decksArray
+        
         if let deck = source?[indexPath.row] {
-            
             do {
-                
                 if let flashcards = try dataManager?.flashcards(forDeckWithId: deck.id) {
-
 					if let bar = searchBar {
                         searchDecks = nil
                         hideSearchBar(-topItemOffset)

        bar.delegate = self
        view.insertSubview(bar, aboveSubview: decksCollectionView)
        searchBar = bar
        
    }
   
    func cancelSearchReposition(searchBar: UISearchBar, animated: Bool) {

        let spacing = Utils.DeckViewLayout.DecksSpacing
        equalSizeAndSpacing(numberOfCellsInRow: Utils.DeckViewLayout.DecksInRowIPhoneVer, spacing: spacing, collectionFlowLayout: flow)

        decksCollectionView.backgroundColor = UIColor.sb_Grey()
        
        let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(DecksViewController.hideKeyboard))
        swipeGestureRecognizer.direction = [.Down,.Up]
        decksCollectionView.addGestureRecognizer(swipeGestureRecognizer)
        swipeGestureRecognizer.delegate = self
    }
    
    override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
            if keyPath == "openSide",let newSide = change?["new"] as? Int, let oldSide = change?["old"] as? Int where newSide != oldSide {
                if newSide != 0 {
                    hideSearchBar(navbarHeight)
                } else {
                    hideSearchBar(-topItemOffset)
                }
            }
    }
    
    // this function calculate size of decks, by given spacing and number of cells in row
