私はこのエラーを理解できません:
キャッチされていない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。理由: '*** setObjectForKey: キーを nil にすることはできません
ここにいくつかのサンプル JSON があります
[{"storeId":"22","storeName":"Jewel Osco","storeAddress1":"890 N Western Ave","storeAddress2":"","storeCity":"Lake Forest","storeState":"IL","storeZipCode":"","storeGfCount":"71","storeListCount":"2","storeDistance":"1.13","products":[{"storeId":"22","productId":"61","upcCode":"00090800000751","brandDesc":"Herb Pharm","productName":"Herb Pharm Black Elderberry Herbal Glycerite Extract"},{"storeId":"22","productId":"64","upcCode":"00698997807308","brandDesc":"Udi's","productName":"Udi's Soft N' Chewy Granola Bars Chocolate Chip - 5 CT"}]}]
これは、1 対多の製品配列を持つ店舗の配列です。
リレーションシップなしでクエリを実行すると、完全に実行されます。ただし、関係を追加すると失敗します。
関連するマッピングは次のとおりです。
class func defaultMapping(objectManager:RKObjectManager!) -> RKEntityMapping{
let managedObjectStore:RKManagedObjectStore = objectManager.managedObjectStore!
let defaultMapping = RKEntityMapping(forEntityForName: "LocatorStoreProduct", inManagedObjectStore: managedObjectStore)
defaultMapping.identificationAttributes = ["productId","storeId"]
let mappingDictionary:[String:String] = [
"productId":"productId" ,
"storeId":"storeId" ,
"upcCode":"upcCode" ,
"brandDesc":"brand" ,
"productName":"productName"
]
defaultMapping.addAttributeMappingsFromDictionary(mappingDictionary)
return defaultMapping
}
マッピングの割り当ては次のとおりです。
class func defaultMapping(objectManager:RKObjectManager!) -> RKEntityMapping{
let managedObjectStore:RKManagedObjectStore = objectManager.managedObjectStore!
let defaultMapping = RKEntityMapping(forEntityForName: "LocatorStore", inManagedObjectStore: managedObjectStore)
defaultMapping.identificationAttributes = ["extId"]
let mappingDictionary:[String:String] = [
"storeId":"extId" ,
"storeName":"storeName" ,
"storeAddress1":"address1" ,
"storeAddress2":"address2" ,
"storeCity":"city" ,
"storeState":"state" ,
"storeZipCode":"zipCode" ,
"stoerGfCount":"totalCount",
"storeListCount":"inListCount",
"storeDistance":"distance"
]
defaultMapping.addAttributeMappingsFromDictionary(mappingDictionary)
//HERE IS MY RELATIONSHIP MAPPING:
let lspMapping = LocatorStoreProduct.defaultMapping(objectManager)
let relationshipMapping = RKRelationshipMapping(fromKeyPath: "products", toKeyPath: "locatorStoreProducts", withMapping: lspMapping)
defaultMapping.addPropertyMapping(relationshipMapping)
return defaultMapping
}
これを何時間も見つめていて、どのキーが欠けているのかわかりません