These are the changes I made for the errors from Swift 1 to Swift 2 and also additional notes on the tutorial.
For the warning in line 45, change the selector of userCountBarButtonItem from
userCountBarButtonItem = UIBarButtonItem(title: “1”, style: UIBarButtonItemStyle.Plain, target: self, action: Selector(“userCountButtonDidTouch”))
userCountBarButtonItem = UIBarButtonItem(title: “1”, style: UIBarButtonItemStyle.Plain, target: self, action: #selector(GroceryListTableViewController.userCountButtonDidTouch))
For the error in line 68, change the cell declaration from
let cell = tableView.dequeueReusableCellWithIdentifier(“ItemCell”) as! UITableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier(“ItemCell”, forIndexPath: indexPath)
For the error in line 126 change the textField declaration in line 126 from
let textField = alert.textFields! as! UITextField
let textField = alert.textFields!
For the error in the following line (127) add ! in the groceryItem declaration:
let groceryItem = GroceryItem(name: textField.text, addedByUser: self.user.email, completed: false)
let groceryItem = GroceryItem(name: textField.text!, addedByUser: self.user.email, completed: false)
Change cell declaration in line 46 to clear the error from Swift 1 to Swift 2 from
let cell = tableView.dequeueReusableCellWithIdentifier(UserCell) as! UITableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier(UserCell, forIndexPath: indexPath)
Additionally, In LoginViewController.swift
I changed the alert in line 48 from var to let since it does seem to only have one value.
I also changed the emailField and passwordField declarations by removing “as! UITextField” so that it looks like this
let emailField = alert.textFields!
let passwordField = alert.textFields!
but I don’t recall if this was absolutely necessary.
As for the tutorial itself, I have some notes:
In section Displaying a List of Online Users
- The tutorial says to change viewDidAppear but there is no viewDidAppear code, do we add it or was viewDidLoad the intended function? (both seem to work)
- In OnlineUsersTableViewController.swift there is no reference to usersRef like in GroceryListTableViewController.swift, yet the tutorial assumes you already do or you already imported it. So, does it need to be added in the same way we did in the other file or should it be imported? (I just added it)
- For the last piece of code to be added in this section, change enumerate(self.currentUsers) and instead use self.currentUsers.enumerate() as the former gives error (I guess due to the Swift 2 changes).
- The tutorial says “Using a bit of trickery, it’s possible to add a user to Online…” if this sounded a bit ambiguous as there is no explicit mention of what that trickery means, the actual trick is to press the + button in the online data tree
Lastly, in the section Enabling Offline
The code for AppDelegate.swift that we’re supposed to add is already added there in the starter project.
Hope this helps