Search code examples
iosasynchronousplistnsdatansfilemanager

How to save plist after downloading it


I'm downloading a .plist like this:

dispatch_async(kBgQueue, ^{
            NSError* error = nil;
            NSData* data = [NSData dataWithContentsOfURL:kFeedURL options:NSDataReadingUncached error:&error];
            if (error) {
                //NSLog(@"Feed error: %@", [error localizedDescription]);                    
            } else {
                [self performSelectorOnMainThread:@selector(fetchedData:)
                                       withObject:data waitUntilDone:YES];
            }

        });

But how do I convert the data back to a plist and save it to the app?

- (void)fetchedData:(NSData *)responseData {
    //???
}

Solution

  • It's hard to tell you what to do without more information. You say you're downloading a plist, but then ask how to convert the data back to a plist. If it's a serialized plist, then you probably want to use the NSPropertyListSerialization class method, propertyListWithData:options:format:error: to convert it to a plist object. That method returns an object typed id, so you probably should log the class of the object, to see what you actually got, and then use one of the save methods from that class to save the data.