我有一个 NSMutableArray 保存到我的服务器,当我通过此代码返回它时:
[AsyncURLConnection request:url completeBlock:^(NSData *data) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (![myString isEqualToString:@"0"]) {
[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:myString] forKey:@"savedArray"];
NSArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] objectForKey:@"savedArray"]];
contactsArray = [[NSMutableArray alloc] initWithArray:oldSavedArray];
[table reloadData];
}else{
contactsArray = [[NSMutableArray alloc] init];
}
});
});
} errorBlock:^(NSError *errorss) {
}];
oldSavedArray 数组返回:
(
(
"Andrew Dunn",
"andrew@dunn-carabali.com",
accept
),
(
"John Appleseed",
"John-Appleseed@mac.com",
alert
)
)
但
contactsArray = [[NSMutableArray alloc] initWithArray:oldSavedArray];
总是用
-[__NSCFString count]: unrecognized selector sent to instance
我已经尝试了我能想到的所有可能的方法来解决这个问题,所以我对下一步该怎么做或如何将 NSMutableArray 保存到我的服务器感到困惑,以便成员在登录或使用不同的设备时可以检索它,不浪费数据库空间。