我收到了这个错误信息:“有条件绑定的初始化器必须具有可选类型,而不是“NSManagedObjectContext”。”
我不确定如何修复此错误。我认为问题出在“if let”语句上。
我不确定如何修复此错误。我认为问题出在“if let”语句上。
if let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext {
restaurant = NSEntityDescription.insertNewObjectForEntityForName("Restaurant",
inManagedObjectContext: managedObjectContext) as! Restaurant
restaurant.name = nameTextField.text
restaurant.type = typeTextField.text
restaurant.location = locationTextField.text
restaurant.image = UIImagePNGRepresentation(imageView.image!)
restaurant.isVisited = isVisited
//restaurant.isVisited = NSNumber.convertFromBooleanLiteral(isVisited)
var e: NSError?
if managedObjectContext.save() != true {
print("insert error: \(e!.localizedDescription)")
return
}
}