Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve a nested NSDictionary from property list
    primarykey
    data
    text
    <p>I want to save data in a property list in one view and retrieve it in another view. The structure of the data that I'm saving looks like this:</p> <p>Key: (NSString) Value (NSDictionary)</p> <p>The <code>NSDictionary</code> just contains strings for both keys and values. Whenever a button is pressed, I fire this method to do the saving:</p> <pre><code>- (IBAction)saveRSSItem:(id)sender { NSMutableDictionary *dictionary; if ([[NSFileManager defaultManager] fileExistsAtPath:[self dataFilePath]]){ dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:[self dataFilePath]]; } else { dictionary = [[NSMutableDictionary alloc] init]; } //Create Dictionary to store RSSItem information NSMutableDictionary *RSSdictionary = [[NSMutableDictionary alloc] init]; if (self.selectedItem.title) [RSSdictionary setValue:@"title" forKey:self.selectedItem.title]; if (self.selectedItem.summary) [RSSdictionary setValue:@"summary" forKey:self.selectedItem.summary]; if (self.selectedItem.author) [RSSdictionary setValue:@"author" forKey:self.selectedItem.author]; if (self.selectedItem.date) [RSSdictionary setValue:@"date" forKey:self.selectedItem.date]; if (self.selectedItem.content) [RSSdictionary setValue:@"content" forKey:self.selectedItem.content]; //Add saved RSSItem to dictionary [dictionary setValue:RSSdictionary forKey:self.selectedItem.title]; //Overwrite the updated dictionary in the property list NSURL *url = [[NSURL alloc] initFileURLWithPath:[self dataFilePath]]; [dictionary writeToURL:url atomically:YES]; } </code></pre> <p>When I'm trying to retrieve the data I do something like this:</p> <pre><code>NSDictionary *savedRSSItemsDictionary = [NSDictionary dictionaryWithContentsOfFile:[self propertyListFilePath]]; NSDictionary *RSSDictionary = [savedRSSItemsDictionary objectForKey:[savedRSSItemsArray objectAtIndex:indexPath.row]]; </code></pre> <p>The first line retrieves the root dictionary. The second line retrieves a the value of the first row in the property list (which is an <code>NSDictionary</code>).</p> <p>However, I can't use the method valueForKey: on <code>RSSDictionary</code>. It seems like its not an <code>NSDictionary</code>? Any ideas why I can't retrieve an <code>NSDictionary</code> when it is in the value field of a property list? Do I need to use <code>NSPropertySerialization</code>?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload