Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:57:47+00:00 2026-06-02T05:57:47+00:00

Given this P-List Dictionary: How do I get at the 3rd. Key – Dinner

  • 0

Given this P-List Dictionary:

enter image description here

How do I get at the 3rd. Key – “Dinner” – which in itself is also a Dictionary, and parse its values correctly?

Or, should I structure this P-List differently to begin with, so I can get at everything more easily?

Here’s what I got, starting by grabbing all the Keys from my ‘MenuDictionary’ and storing them in an Array:

// Load the Property-List file into the Dictionary:
MenuDictionary = [[NSDictionary alloc] initWithContentsOfFile:menuPath];

// Get all the Keys from the Dictionary, put 'em into a 'mealTimesArray':
mealTimesArray = [[MenuDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];

// For each meal-type KEY, grab all the Values (dishes) in it and store them in a 'mealDishesArray':
for (NSString *mealTime in mealTimesArray) {
    NSArray *mealDishesArray = [MenuDictionary valueForKey:mealTime];

    // Now I can iterate through the 'mealDishesArray' to access each dish at
    // a time, so I can print them out or do whatever else:
    for (NSString *dish in mealDishesArray) {
        NSLog(@"Iterating through 'mealDishesArray' now...");
        NSLog(@"Current 'dish' is: %@", dish);

The problem occurs when I get to the “Dinner” key: its a Dictionary, containing 2 Keys with 2 array Values. So how do I load its contents into a Dictionary object? More specifically, what ‘init’ method should I be using to load the “Dinner” contents into my new Dictionary object?

I tried this – doesn’t work:

// I put this inside the first fast-enum loop:

if ([mealTime isEqualToString: @"Dinner"]) {
   // init new Dictionary object (declared previously):
   dinnerDictionary = [[NSDictionary alloc] initWith ???];

I’d like to init it with the contents of the “Dinner” Key, but its not a P-List file obviously, so I can’t use

   initWithContentsOfFile: pathName

I don’t understand which of the other init methods will give me access to both the Keys and Values of “Dinner”. Because even though “Dinner” is structured as a Dictionary, its currently sitting inside an Array, which doesn’t regard it as a Dictionary (I think…)

I’m a little unclear about this obviously.

Or, should I be structuring my P-List differently to begin with so I can get at this nested Dinner dictionary?

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:57:49+00:00Added an answer on June 2, 2026 at 5:57 am

    I think plist structure makes sense, and dealing with the contents conditionally based on class is perfectly okay, too. I would react to what’s in the plist within a reasonable range of expectations, so…

    // for each meal...
    for (NSString *mealTime in mealTimesArray) {
        // we're not sure what kind of meal we have
        id mealInfo = [MenuDictionary valueForKey:mealTime];
    
        if ([id isKindOfClass:[NSArray self]]) {
            // it's an array? cast as an array and deal with the array
            NSArray *mealDishesArray = (NSArray *)mealInfo;
            [self handleMealArray:mealDishesArray];
        } else if ([id isKindOfClass:[NSDictionary self]]) {
            // it's a dictionary?  that's cool, too. cast as a dictionary and deal with it
            NSDictionary *mealDictionary = (NSDictionary *)mealInfo;
            [self handleMealDictionary:mealDictionary];
        }
    }
    
    // you've worked out to handle the array
    - (void)handleMealArray:(NSArray *)mealDishesArray {
        for (NSString *dish in mealDishesArray) {
            NSLog(@"Iterating through 'mealDishesArray' now...");
            NSLog(@"Current 'dish' is: %@", dish);
        }
    }
    
    // handle the dictionary like a dictionary, realizing that it contains
    // arrays, which you've already worked out how to handle
    - (void)handleMealDictionary:(NSDictionary *)mealDictionary {
        for (NSString *dishType in [mealDictionary allKeys]) {
            NSArray *mealDishesArray = [mealDictionary valueForKey:dishType];
            [self handleMealArray:mealDishesArray];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function which removes occurrences of a given element within the list
How do I get a tuple/list element given a condition in python? This occurs
Given this code: List<string> things = new List<string>(); foreach (string thing in things) {
Given this piece of code : public static void writeFile(File file,List buffer)throws IOException{ File
given this html: <li id=the_list_item><img src=some_img></li> and this selectior: $(#the_list_item) I want to get
given this xml: <root> <list> <!-- foo's comment --> <item name=foo /> <item name=bar
Given a list like this: num = [1, 2, 3, 4, 5] There are
Given a list of dictionaries like this: x = [ {'name':'a', 'student': 1 ,
This portion of code checks if a number given (First element in a list)
So is it possible to get a dictionary/list of the attributes ONLY for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.