ios:内存文件运算符布尔崩溃

时间:2019-04-03 10:15:59

标签: ios swift database nullpointerexception realm

我在我的项目中使用了realmswift,因此按照苹果的指导方针,我将整个项目转换为swift 4.2,并将所有pod库转换为最新版本。项目已成功转换,但是每次运行项目时都会崩溃。

我上传了屏幕截图以便更好地理解。

Crash image

现在这是我在数据库中插入值的模型

class SyncProductModel: Object, Mappable {
    @objc dynamic var id: String?
    @objc dynamic var productType : Int = 0
    @objc dynamic var name: String?
    @objc dynamic var category :String?
    @objc dynamic var sku : String?
    @objc dynamic var baseMOQ : Double = 0.0
    @objc dynamic var isActive : Bool = false
    @objc dynamic var isFavourite : Bool = false
    @objc dynamic var createdAt : String?
    @objc dynamic var updatedAt : String?
    @objc dynamic var uom : String?
    @objc dynamic var productDesc : String?
    @objc dynamic var retailUOM : String?
    @objc dynamic var isInCart : Bool = false

    var isSelecetd = false
    var attachments = List<AttachmentModel>()
    var inventory = List<SyncInventoryModel>()

    var inventoryModel : SyncInventoryModel?

//    var tags = List<tags>()
//    var baseProperties = List<baseProperties>()

    required convenience init?(map: Map) {
        self.init()
    }

    override class func primaryKey() -> String? {
        return "id"
    }

    func mapping(map: Map) {

        id                   <- map["id"]
        productType          <- map["type"]
        name                 <- map["name"]
        category             <- map["category"]
        sku                  <- map["sku"]

        var baseQty          : Any?
        baseQty              <- map["baseMOQ"]

        baseMOQ              = Utilities.getDoubleValue(value: baseQty)
        isActive             <- map["isActive"]
        createdAt            <- map["createdAt"]
        updatedAt            <- map["updatedAt"]
        uom                  <- map["uom"]
        productDesc          <- map["description"]
        retailUOM            <- map["retailUOM"]

        attachments          <- (map["attachments"], ListTransform<AttachmentModel>())
//        tags                 <- (map["attachments"], ListTransform<tags>())
//        baseProperties       <- (map["baseProperties"], ListTransform<baseProperties>())

    }

这是我在db中插入值的代码

        for obj in masterProduct
        {
            if self.realm.isInWriteTransaction {
                self.realm.add(obj, update: true)
            }
            else {
                try! self.realm.write {
                    // Here My application get crashed.
                    self.realm.add(obj, update: true)
                }
            }
         }

但是每次应用程序崩溃。请帮我,我被困在这里。

任何帮助将不胜感激。

0 个答案:

没有答案