0
魔法記錄核心數據錯誤「CoreData:錯誤:嚴重的應用程序錯誤,在覈心數據更改處理過程中發生異常,這通常是NSManagedObjectContextObjectsDidChangeNotification觀察者中的一個錯誤 - [__ NSCFSet addObject:]:嘗試插入比零USERINFO(NUL」魔法記錄核心數據錯誤
func insertChecklistItem(checklistst:Checklist,checklistItemDictionary:NSDictionary, localContext:NSManagedObjectContext) -> Bool
{
var isInserted = false
MagicalRecord.save ({
(context:NSManagedObjectContext) in
let checklistItem:ChecklistItem = ChecklistItem.mr_createEntity(in: localContext)!
if checklistItemDictionary.value(forKey: "id") != nil
{
checklistItem.itemId = checklistItemDictionary.value(forKey: "id")! as? String
}
if checklistItemDictionary["description"] != nil
{
checklistItem.itemDescription = checklistItemDictionary.value(forKey: "description")! as? String
}
if checklistItemDictionary.value(forKey: "name") != nil
{
let NameDicitonary = checklistItemDictionary.value(forKey: "name")! as? NSDictionary
checklistItem.name = NameDicitonary?.value(forKey: "text") as? String
}
let sequanceNumber = checklistItemDictionary["sequencenumber"]! as! NSDictionary
if sequanceNumber["text"] != nil
{
let sequanceNumberText = Int(sequanceNumber["text"]! as! String)
checklistItem.sequencenumber = sequanceNumberText as NSNumber?
}
checklistItem.checklist = checklistst
if let scaleDictionary = checklistItemDictionary.value(forKey: "scale")
{
isInserted = insertScale(checklistItem: checklistItem, scaleDictionary: scaleDictionary as! NSDictionary, localContext: localContext)
}
print("------------CRASH \(checklistItemDictionary["checklistitem"])")
if checklistItemDictionary["checklistitem"] != nil
{
if checklistItemDictionary["checklistitem"]! is NSArray
{
let checklistItems = checklistItemDictionary["checklistitem"]! as! NSArray
for item in checklistItems
{
let checklistSubItemDicitonary = item as! NSDictionary
insertChecklistSubItem(checklistst: checklistst, checklistItemDictionary: checklistSubItemDicitonary, localContext: localContext, parentId: checklistItem.itemId!)
}
}
else
{
}
}
}
)
let data = ChecklistItem.mr_findAll()
for d1 in data!
{
let d:ChecklistItem = d1 as! ChecklistItem
print(d.itemId,d.itemDescription,d.name,d.checklist)
}
return isInserted
}
一切行之有效的SWIFT 2.3。更新到SWIFT 3.0後,上面的錯誤提前來了。謝謝你。