我有一串与他们的位置有关的照片网址(例如:googleusercontent.com/photo.gif)。我使用“二进制数据”类型将单个字符串(该字符串可能包含其他四个 url)保存到 Core Data。当我从核心数据中检索 url 时,它会正确显示字符串的数量,但不会在 for 循环之外显示正确的数据。
// Loop through the photo selection to get the urls
for (int i=0; i < self.tempPhotos.count; i++)
{
self.photo = [ self.tempPhotos objectAtIndex:i];
self.image = [ photo originalImage];
NSString *urls = [image.URL absoluteString]; // <-- here we get the urls and store
self.selected_urls = urls;
NSData * data = [NSKeyedArchiver archivedDataWithRootObject:urls];
self.group.selectedurl = data; // assign it to the core data object
}
// Now we're out of the for loop, here is where it will not retrieve and log properly. if i put this inside the for loop, it will. why is that?
NSMutableArray *temp = [NSMutableArray *)[NSKeyedUnarchiver unarchiveObjectWithData:self.group.selectedurl];
NSLog(@"%@",temp);
如果我将 NSLog 放在 for 循环中,我会正确理解它。它应该看起来像这样: - “googleusercontent.com/photo1.gif” - “googleusercontent.com/photo2.gif”
当我在 for 循环之外检索核心数据对象时,它给了我这个:-“googleusercontent.com/photo1.gif”-“googleusercontent.com/photo1.gif”
我不知道为什么它在 for 循环内工作,但它在外面的任何地方都不能正常工作,我觉得我错过了一个明显的步骤。我可以帮忙吗?