从Core Data获取结果时,应用程序经常崩溃

时间:2016-06-20 11:42:22

标签: ios swift core-data

我得到一个NSManagedObjectContext,如下所示:

let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext

然后:

    var fetchResults: [AccountEntity]?
    do {
        let fetchRequest = NSFetchRequest(entityName: "AccountEntity")
        fetchResults = try self.managedObjectContext.executeFetchRequest(fetchRequest) as? [AccountEntity]
    } catch {}

    if let accounts = fetchResults {
        for a in accounts {
            if let name = a.name as String! {
                self.nameTextView.text = name // crash
            }
        }
    }

它有时会获取数据并在屏幕上正确显示名称。其他时候崩溃并说EXC_BAD_INSTRUCTION ......

有时我会收到此错误:

pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

我添加了malloc_error_break作为符号断点,它确实停止了,但我不知道如何解释它显示的汇编代码。

0 个答案:

没有答案