Swift 2 - 传递给不带参数的调用的参数
Swift 2 - Argument passed to call that takes no arguments
我正在尝试在我的模型 class 上调用 save
函数,但是即使它适用于 1.2,它也会在 2.1 中抛出此错误:
Argument passed to call that takes no arguments
func save() -> NSError?{
var error: NSError?
self.context?.save(error) // Error: Argument passed to call that takes no arguments
return error
}
编辑:
我将代码转换为:
func save() -> NSError?{
do {
try context!.save()
} catch let error as NSError? {
print("error saving core data: \(error)")
}
}
...但现在我收到了:
Missing return in a function expected to return 'NSError?'
我不知道这个方法或子类,但你可以尝试使用你的错误变量的指针。
self.context?.save(&error)
在 swift 2.0 中 context.save 函数实现根据新的错误处理进行了更改!
改为
do{
try context!.save()
}catch let error as NSError{
print("error saving core data: \(error)")
}
func save() -> NSError?{
do {
if let context = context {
try context.save()
}
} catch let error as NSError? {
print("error saving core data: \(error)")
return error
}
return nil
}
我正在尝试在我的模型 class 上调用 save
函数,但是即使它适用于 1.2,它也会在 2.1 中抛出此错误:
Argument passed to call that takes no arguments
func save() -> NSError?{
var error: NSError?
self.context?.save(error) // Error: Argument passed to call that takes no arguments
return error
}
编辑:
我将代码转换为:
func save() -> NSError?{
do {
try context!.save()
} catch let error as NSError? {
print("error saving core data: \(error)")
}
}
...但现在我收到了:
Missing return in a function expected to return 'NSError?'
我不知道这个方法或子类,但你可以尝试使用你的错误变量的指针。
self.context?.save(&error)
在 swift 2.0 中 context.save 函数实现根据新的错误处理进行了更改!
改为
do{
try context!.save()
}catch let error as NSError{
print("error saving core data: \(error)")
}
func save() -> NSError?{
do {
if let context = context {
try context.save()
}
} catch let error as NSError? {
print("error saving core data: \(error)")
return error
}
return nil
}