不能援引“拯救”与类型的参数列表“(无)”

问题描述:

需要帮助的打击代码。刚刚更新到Xcode的7测试版不能援引“拯救”与类型的参数列表“(无)”

我得到以下错误“无法调用‘保存’有说法类型“(无)'”的列表。这是在IOS 6的工作

import UIKit 
import CoreData 

class ItemViewController: UIViewController { 
@IBOutlet weak var textFieldDiveNumber: UITextField! 
@IBOutlet weak var textFieldDiveDate: UITextField! 
@IBOutlet weak var textFieldDiveLocation: UITextField! 


override func viewDidLoad() { 
    super.viewDidLoad() 

    // Do any additional setup after loading the view. 
} 
@IBAction func saveTapped(sender: AnyObject) { 

    let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 

    let contxt: NSManagedObjectContext = appDel.managedObjectContext 
    let en = NSEntityDescription.entityForName("List", inManagedObjectContext: contxt) 

    var newItem = Model(entity: (en)!, insertIntoManagedObjectContext: contxt) 

    newItem.divenumber = textFieldDiveNumber.text! 
    newItem.divedate = textFieldDiveDate.text! 
    newItem.divelocation = textFieldDiveLocation.text! 

    contxt.save(nil) 



    self.navigationController?.popToRootViewControllerAnimated(true) 
} 


override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 



} 
+0

你有没有试过'NULL'? – luk2302

+0

是的,我有,它声明NULL不可用,使用'nil'而不是这个导入的宏 – Scubadivingfool

自上周一以来这已经被问了好几次,但要找到&标记重复从SE iOS应用很麻烦,所以...

在斯威夫特2,NSManagedObjectContext“ s save()方法标记为throws,因此您必须处理来自它的任何错误。 (并且你不通过一个错误指针作为参数。)

你的Swift 1代码忽略了错误;雨燕2相当于是一个空catch

do { 
    try context.save() 
} catch { 
    // you can go about your business. move along. 
} 

忽略错误是不是一个好主意,但。如果你不想让错误的用户恢复的做一些有用的事情在catch,只是计划崩溃的错误:

try! context.save() 

感谢名单Rickster,我也碰到过,并试图您的方法,在当天早些时候但它不起作用。 但是,当你重新发布你的答案时,我只用这次“contxt”而不是“context”来试用它,它工作。 非常感谢。 此致敬礼。 Del