Reputation: 79
I am trying to learn Swift and decided to use "Swift for Dummies" published in 2015. The sample code used in the book is for XCode 6.X but I am using Xcode 7.2.1.
In chapter 4, there is a code for configureCell in MasterViewController.swift but it is not compatible for Xcode 7.X
Dummies has the following:
func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath) {
let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as Event
cell.textLabel!.text = "latitude: " + object.latitude.description + " longitude: " + object.longitude.description
}
Xcode 7.X does not use indexPath and I don't have a clue of how to recode the func.
func configureCell(cell: UITableViewCell, withObject object: NSManagedObject) {
/* I mangled the code inside the braces so I decided not to reproduce it here*/
}
Thanks in advance for your help.
I have recoded the function to the best of my abilities and now Xcode no longer reports an error. Is the following code correct?
func configureCell(cell: UITableViewCell, withObject object: NSManagedObject) {
let objectgt = object as! Event
cell.textLabel!.text = "latitude: " + objectgt.valueForKey("latitude")!.description + " longitude: " + objectgt.valueForKey("longitude")!.description
}
Upvotes: 0
Views: 283
Reputation: 5303
I'm sorry to be the bearer of bad news, but I honestly think you should not use such an outdated book. You'll spend a lot of time learning things that no longer work. As the commenters above mentioned, swift has changed a lot, and so has Xcode. If you finish the book, you would still be at a great disadvantage compared to those who are using current tools (and the current language).
I recommend you try the "HackingWithSwift" website for a free resource to get you started (40 free example tutorials) at https://www.hackingwithswift.com [or something similar], and then decide how you want to proceed. You should use current tools, and at least Swift 3.1 or you will have difficulties understanding new code.
One last thought: Swift has gotten easier since XCode6 days. The method calls/parameters are now more consistent and easier to work with. That will help make the learning process smoother and more enjoyable. 🍀
Upvotes: 1