我有,我用它來更新行已經改變了境界封閉: 斯威夫特字典需要長時間來編譯
try realm.write {
realm.create(Product.self, value: ["itemgroup": item.itemgroup,
"itembrand": item.itembrand,
"itemtype": item.itemtype,
"itemsubtype": item.itemsubtype,
"basedescription": item.basedescription,
"info": item.info,
"upc": item.upc,
"upc2": item.upc2,
"upc3": item.upc3,
"upc4": item.upc4,
"upc5": item.upc5,
"baseprice": item.baseprice,
"proprice": item.proprice,
"retailprice": item.retailprice,
"stdprice": item.stdprice,
"caseqty": item.caseqty,
"spord": item.spord,
"category": item.category,
"categorycode": item.categorycode,
"allowinbc": item.allowinbc,
"allowinab": item.allowinab], update: true)
}
然而,它採取了10分鐘編譯!
這裏是我的模型類:
class Product: Object {
dynamic var itemno: String = ""
dynamic var itemgroup: String = ""
dynamic var itembrand: String = ""
dynamic var itemtype: String = ""
dynamic var itemsubtype: String = ""
dynamic var basedescription: String = ""
dynamic var info: String = ""
dynamic var upc: String = ""
dynamic var upc2: String = ""
dynamic var upc3: String = ""
dynamic var upc4: String = ""
dynamic var upc5: String = ""
dynamic var baseprice: Double = 0.00
dynamic var proprice: Double = 0.00
dynamic var retailprice: Double = 0.00
dynamic var stdprice: Double = 0.00
dynamic var caseqty: Int = 0
dynamic var spord: String = ""
dynamic var category: String = ""
dynamic var categorycode: String = ""
dynamic var allowinbc: String = ""
dynamic var allowinab: String = ""
override class func primaryKey() -> String {
return "itemno"
}
convenience init(itemno: String, itemgroup: String, itembrand: String, itemtype: String, itemsubtype: String, basedescription: String, info: String, upc: String, upc2: String, upc3: String, upc4: String, upc5: String, baseprice: Double, proprice: Double, retailprice: Double, stdprice: Double, caseqty: Int, spord: String, category: String, categorycode: String, allowinbc: String, allowinab: String) {
self.init()
self.itemno = itemno
self.itemgroup = itemgroup
self.itembrand = itembrand
self.itemtype = itemtype
self.itemsubtype = itemsubtype
self.basedescription = basedescription
self.info = info
self.upc = upc
self.upc2 = upc2
self.upc3 = upc3
self.upc4 = upc4
self.upc5 = upc5
self.baseprice = baseprice
self.proprice = proprice
self.retailprice = retailprice
self.stdprice = stdprice
self.caseqty = caseqty
self.spord = spord
self.category = category
self.categorycode = categorycode
self.allowinbc = allowinbc
self.allowinab = allowinab
}
}
我可以做我的代碼,將加快編制是什麼?
謝謝。
在您的示例代碼,什麼'item'的類型? – idz
@idz''item''是類型'Product',我的模型類。這是一個常量,它包含一個用便利初始值設定項實例化的Product的實例。 – Sicypher
幾乎完美通過https://spin.atomicobject.com/2016/04/26/swift-long-compile-time/ – BallpointBen