线程1:swift中的EXC_BAD_ACCESS(代码:1,地址:0x70)

时间:2015-11-04 06:44:59

标签: ios multithreading core-data swift2

我收到以下错误:主题1:

  AppDelegate中的

EXC_BAD_ACCESS(代码:1,地址:0x70)。

我在我的应用程序中使用CoreData,但是当我删除coreData时,它运行正常。但是,添加CoreData后我的应用程序崩溃了

当我运行应用程序时,此消息进入调试区域:

  

无法在NSManagedObject类' IndustryInsights.IICategoryDAO'

上调用指定的初始值设定项

当应用崩溃时,它只打印(lldb)

所以请帮我解决这个问题。

这是我的NSManagedObject类

import Foundation
import CoreData

class IICategoryDAO: NSManagedObject{

    lazy var coreDataStore: IICoreDataStore = {
        let coreDataStore = IICoreDataStore()
        return coreDataStore
    }()

    lazy var coreDataHelper: IICoreDataHelper = {
        let coreDataHelper = IICoreDataHelper()
        return coreDataHelper
    }()

func insertCategory()
{
    print(" ======== Insert ======== ")

        let newItem: IICategoryModel = NSEntityDescription.insertNewObjectForEntityForName("Category", inManagedObjectContext: coreDataHelper.backgroundContext!) as! IICategoryModel

        newItem.categoryName = "Category-Name"
        newItem.subCategoryName = "Sub-category"

        NSLog("Inserted New Category ")

    self.coreDataHelper.saveContext(self.coreDataHelper.backgroundContext!)

}

// fetch Category
func fetchcategory() -> [IICategoryModel]
{
    NSLog(" ======== Fetch ======== ")
    var error: NSError? = nil
    let fetchRequest: NSFetchRequest = NSFetchRequest(entityName: "Category")

    var result = [IICategoryModel]()
    do {
        result = try self.coreDataHelper.managedObjectContext.executeFetchRequest(fetchRequest) as! [IICategoryModel]

    } catch let nserror1 as NSError{
        error = nserror1
        print("\(error)")

    }

    return result
}

 func deleteCategory()
{
    let fetchRequest = NSFetchRequest(entityName: "Category")
    var result = [IICategoryModel]()
    do {
        result = try self.coreDataHelper.managedObjectContext.executeFetchRequest(fetchRequest) as! [IICategoryModel]
    } catch let nserror1 as NSError
    {
                    print("\(nserror1)")
    }
    if result.isEmpty {
        NSLog("Deleted All Families")
    }
    else{
        for resultItem in result {
            let categoryItem = resultItem 
            NSLog("Fetched Error Category for \(categoryItem.categoryName) ")
        }
    }

}


import Foundation
import CoreData

@objc(IICategoryModel)
class IICategoryModel: NSObject
{
    var categoryName: String = ""
    var subCategoryName: String = ""
}

我引用这个gitHub库...     https://github.com/iascchen/SwiftCoreDataSimpleDemo

enter image description here

0 个答案:

没有答案