我正在尝试学习Swift并决定使用2015年发布的“Swift for Dummies”。本书中使用的示例代码适用于XCode 6.X,但我使用的是Xcode 7.2.1。
在第4章中,MasterViewController.swift中有一个insertNewObject的代码,但它与Xcode 7.X不兼容。有问题的行是“newManagedObject.setValue.longitude = self.lastLocation.coordinate.longitude”并产生错误“对成员setValue的模糊引用”
func insertNewObject(sender: AnyObject) {
let context = self.fetchedResultsController.managedObjectContext
let entity = self.fetchedResultsController.fetchRequest.entity!
let newManagedObject = NSEntityDescription.insertNewObjectForEntityForName("Event", inManagedObjectContext: context) as! Event
// If appropriate, configure the new managed object.
// Normally you should use accessor methods, but using KVC here avoids the need to add a custom class to the template.
newManagedObject.setValue(NSDate(), forKey: "timeStamp")
newManagedObject.latitude=self.lastLocation.coordinate.latitude
newManagedObject.setValue.longitude = self.lastLocation.coordinate.longitude
// Save the context.
do {
try context.save()
} catch {
abort()
}
}