Beginning Collection Views · Cleaning up the UI | Ray Wenderlich

This is a companion discussion topic for the original entry at

can i use optional array’s count method without unwrap the array?

Being that the array is an optional type, you must unwrap it. You could force unwrap it using the ! operator, but that’s not recommended unless you are absolutely sure there will never be a nil value.

Hey guys thanks for this amazing video tutorial. A quick question please. After activating the editing mode and deleting some cells and then deactivating it, performing the segue becomes kind of random. I have to select a cell twice in order for the application to push details view controller to the navigation controller stack. please help me fix this. Thanks.

Yeah, that’s a definite bug. We’ll be fixing it in the updated course later this year. Thanks for letting us know!

I found an alternative to button reuse:

  1. Create strong button outlets
@IBOutlet private var addButton: UIBarButtonItem!
@IBOutlet private var trashButton: UIBarButtonItem!
  1. In func setEditing(_ editing: Bool, animated: Bool) add the following code
if editing {
    navigationItem.setRightBarButtonItems([trashButton], animated: true)
} else {
    navigationItem.setRightBarButtonItems([addButton], animated: true)
1 Like

@hettiger Thank you for sharing your solution - much appreciated! :]

1 Like

Thank you very much :raised_hands: You helped a lot!

If someone has a problem of hiding trash icon at the moment of the 1st loading, I moved “Trash Bin” in the left corner of NavigationBar in Main.storyboard. So when App has loaded at the 1st time, the bin is hidden behind “Edit” button.