我不知道为什么 Core Data 没有正确保存我的属性。它正确保存内容,但不会排列值(我有两列)。它给了我 16 行而不是我想要的 8 行。“urls”列应与“album_names”对齐,而不是向下推。
模拟器中的 sqlite 文件截图:http: //imgur.com/tTOiqtf
TBAppDelegate.h 文件:
@property(strong, retain) NSData *photoUrls
TBAppDelegate.m 文件:
- (void)requestAlbums
{
[FBRequestConnection startWithGraphPath:@"me/albums/" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
TBAppDelegate *delegate = (TBAppDelegate *)[[UIApplication sharedApplication] delegate];
managedObjectContext = [delegate managedObjectContext];
if (error)
{
}
NSArray *collection = (NSArray *)[result data];
for (int i=0; i < collection.count; i++)
{
NSData *album_names = [NSKeyedArchiver archivedDataWithRootObject:collection];
Everything *everything = (Everything *)[NSEntityDescription insertNewObjectForEntityForName:@"Everything" inManagedObjectContext:managedObjectContext];
everything.album_names = album_names;
NSArray *album = [collection objectAtIndex:i];
NSString *photoQuery = [NSString stringWithFormat:@"%@/photos", [album valueForKey:@"id"]];
[FBRequestConnection startWithGraphPath:photoQuery completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSArray *photoResult = (NSArray *)[result data];
self.photoUrls = [NSKeyedArchiver archivedDataWithRootObject:photoResult];
}];
Everything *urls = (Everything *)[NSEntityDescription insertNewObjectForEntityForName:@"Everything" inManagedObjectContext:managedObjectContext];
urls.urls = self.photoUrls;
NSError *coreError;
if (![managedObjectContext save:&coreError])
{
NSLog(@"%@", coreError);
}
}
}];
}