Hello!
These are the changes I made for the errors from Swift 1 to Swift 2 and also additional notes on the tutorial.
In GroceryListTableViewController.swift
For the warning in line 45, change the selector of userCountBarButtonItem from
userCountBarButtonItem = UIBarButtonItem(title: ā1ā, style: UIBarButtonItemStyle.Plain, target: self, action: Selector(āuserCountButtonDidTouchā))
to
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
to
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![0] as! UITextField
to
let textField = alert.textFields![0]
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)
to
let groceryItem = GroceryItem(name: textField.text!, addedByUser: self.user.email, completed: false)
In OnlineUsersTableViewController.swift
Change cell declaration in line 46 to clear the error from Swift 1 to Swift 2 from
let cell = tableView.dequeueReusableCellWithIdentifier(UserCell) as! UITableViewCell
to
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![0]
let passwordField = alert.textFields![1]
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
Happy coding!