我最近跳轉到使用Xcode7.3.1並轉換我的代碼,但是我在這裏遇到了一些問題,這就是我以前如何使用它Swift1.1但我得到錯誤- [__ NSCFNumber count]:在Swift中發送到實例0x14539180的無法識別的選擇器
- [__ NSCFNumber計數]:無法識別的選擇發送到實例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
}
}
任何^ h elp會被讚賞!!
你能提供一個*謂詞*字符串,你傳遞給你的func嗎? – iSashok
字符串是: - (sno == min:(sno)AND isOnline == 1) – BornShell
我認爲你的謂詞字符串的fetchRequest返回了NSNumber,而不是NSArray,試着修改這個字符串或者發送nil – iSashok