У меня есть класс в swift, который делает словарь, используя строки в ключах и объекты в значениях.например, let dict = ["key":value.key]
.значение всегда является строкой.
Когда я получаю данные в моем классе цели c, для одного типа объекта будет
_TtGCs26_SwiftDeferredNSDictionaryVs11AnyHashableP__$
, а код ожидает nsdictionary.
Теперь, когда код -
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dictionaryFromSwiftClass];
, программа выдает ошибку
********[1235:641121] -[__SwiftValue encodeWithCoder:]: unrecognized selector sent to instance 0x280571380
//making dict in swift class
let dictForAddToCart:NSDictionary =
[
"assoc_prod":[
["assoc_prodID":"92",
"assoc_prodValue":currentSelectedColor,
"productInfo":[
"code":productInfoColor.value(forKey: "code"),
"id":productInfoColor.value(forKey: "id"),
"image":productInfoColor.value(forKey: "image"),
"label":productInfoColor.value(forKey: "label"),
"optionslabel":productInfoColor.value(forKey: "optionslabel"),
"price":productInfoColor.value(forKey: "price"),
"qty":productInfoColor.value(forKey: "qty")]],
["assoc_prodID":"92",
"assoc_prodValue":currentSelectedColor,
"productInfo":[
"code":productInfoColor.value(forKey: "code"),
"id":productInfoColor.value(forKey: "id"),
"image":productInfoColor.value(forKey: "image"),
"label":productInfoColor.value(forKey: "label"),
"optionslabel":productInfoColor.value(forKey: "optionslabel"),
"price":productInfoColor.value(forKey: "price"),
"qty":productInfoColor.value(forKey: "qty")]]
]
"productData":productData,
"qty":currentSelectedQuantity
] as NSDictionary
//saving object in objective c class
- (void)saveCartArray:(NSArray *)arrayToSave {
NSMutableArray *archiveArray = [NSMutableArray arrayWithCapacity:arrayToSave.count];
for (NSMutableDictionary* productDic in arrayToSave) {
NSData *productDicData = [NSKeyedArchiver archivedDataWithRootObject:productDic];
[archiveArray addObject:productDicData];
}
NSUserDefaults *userData = [NSUserDefaults standardUserDefaults];
[userData setObject:archiveArray forKey:@"cart"];
}
//NSLOG of arrayToSave-
{
"assoc_prod" = (
{
"assoc_prodID" = 92;
"assoc_prodValue" = 396;
code = "********.Code.color";
id = 92;
image = "********.Image.empty";
label = "********.Label.color";
optionslabel = Nude;
price = "280.0000";
qty = "0.0000";
},
{
"assoc_prodID" = 180;
"assoc_prodValue" = 388;
code = "********.Code.size";
id = 180;
image = "********.Image.empty";
label = "********.Label.size";
optionslabel = 36;
price = "280.0000";
qty = "0.0000";
}
);
productData = {
additionalParameters = (
);
associatedProd = "someData";
brand = "";
categoryId = 378;
description = "";
image = "http://www.x.com/xyz.jpg";
link = "";
linkDownloads = "";
name = some;
position = 0;
price = 280;
productId = 1421;
qty = 0;
set = 0;
shortDescription = "";
sku = some;
type = some;
wsp = "";
};
qty = 1;
}
)