所以我有一個方法用於下載圖片的「urls」我的應用程序的圖像。它已經在iOS 5中工作了好幾個月,我在我的xcdatamodel中的實體中添加了一個字符串類型的新屬性,並且它停止工作。即使我刪除了該屬性,它仍然不起作用。NSEntity的設置值在iOS 5中爆炸,但不是iOS 6
當我清理xcode並刪除iPad的應用程序表單然後啓動應用程序。
在iOS 5中出現此錯誤:「線程1:EXC_BAD_ACCESS(code = 1,address = 0x1)」,如果我按照堆棧跟蹤發生這種情況,我會在setValue:forKey:
處發生這種情況。
但是,如果我清理並運行在iOS 6中,這工作正常。
- (void)fetchSkinWithCompletion:(void (^)(void))completionBlock failure:(void (^)(void))failureBlock {
NSString *skin = [self skinName];
if (skin) {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/skin/%@", BASE_URL, skin]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (!error) {
NSError *jsonError = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&jsonError];
if (!jsonError) {
Skin *s = (Skin *)[Skin findFirstObjectByAttribute:@"name" withValue:skin inContext:[AppDelegate moc]];
if (s == nil) {
s = [NSEntityDescription insertNewObjectForEntityForName:@"Skin" inManagedObjectContext:[AppDelegate moc]];
}
for (NSString * key in json) {
/******** THIS IS WHATS BLOWING UP IN iOS 5 *************/
[s setValue:[json objectForKey:key] forKey:key];
}
[[AppDelegate moc] save:nil];
self.selectedSkin = s;
[self downloadImageAssetsForSkin:self.selectedSkin completionBlock:completionBlock];
return;
} else {
DLog(@"Error parsing JSON:%@", jsonError);
}
} else {
DLog(@"User with Device ID:%@ failed fetch skin with error:%@.", [AppDelegate uniqueID], error);
}
}
failureBlock();
return;
}
findFirstObjectByAttribute:withValue:inContext
是NSManaged Object上的一個附加項。
+ (NSManagedObject *)findFirstObjectByAttribute:(NSString *)attr_name withValue:(id)value inContext:(NSManagedObjectContext *)context {
NSFetchRequest *fetch = [[NSFetchRequest alloc] initWithEntityName:NSStringFromClass([self class])];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == %@", attr_name, value];
fetch.predicate = predicate;
fetch.fetchLimit = 1;
NSError *error = nil;
NSArray *results = [context executeFetchRequest:fetch error:&error];
if (results.count > 0) {
return [results objectAtIndex:0];
}
return nil;
}
需要一些來自你的Skin類的代碼。具體來說,'+ findFirstObjectByAttribute:withValue:inContext:'做什麼? –
更新,希望有所幫助。 – mwoods79
什麼是您的核心數據堆棧設置?你只有一個上下文嗎? – hatunike