我最近跳过使用Xcode7.3.1并转换我的代码,但我在这里遇到了一些问题,这就是我以前在Swift1.1中使用它的方法,但是我收到了错误
- [__ NSCFNumber count]:无法识别的选择器发送到实例0x14539180
这是我的代码:
func deleteData(modelName:String, predicate:String!) -> Bool {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let cdhObj = appDelegate.cdh
let fReq: NSFetchRequest = NSFetchRequest(entityName: modelName)
print("\(fReq)")
print("\(predicate)")
//Check whether predicate is there
if (predicate != nil) {
fReq.predicate = NSPredicate(format:predicate)
print("fReq.predicate-------\(fReq.predicate)")
}
print("Reached Here_1")
print("Reached Here\(fReq.predicate!)")
var result = try! cdhObj.managedObjectContext!.executeFetchRequest(fReq) //getting error in this line
print("Reached Here_2")
for resultItem in result {
let countryItem: AnyObject = resultItem
cdhObj.managedObjectContext!.deleteObject(countryItem as! NSManagedObject)
}
cdhObj.saveContext(cdhObj.managedObjectContext!)
result = try! cdhObj.managedObjectContext!.executeFetchRequest(fReq)
if result.isEmpty {
return true
} else {
return false
}
}
任何帮助都会得到赞赏!!