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 6908135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:31:27+00:00 2026-05-27T08:31:27+00:00

I’m pretty new to Objective C, and I’m having trouble reading values from a

  • 0

I’m pretty new to Objective C, and I’m having trouble reading values from a plist into a set of NSArrays. I tried referencing this question but had no luck.

I have 3 arrays that I am trying to load into my picker. The 3 arrays I want to load in are the arrays conversions, typesFrom, and typesTo. typesFrom and typesTo contain the same values, but change depending on the type of conversion.

Currently, the picker will load with 3 columns but no rows. I feel like there’s probably a simple solution, but I’ve been trying for hours and can’t seem to find it.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    // Grab information from the plist
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath = [bundle 
        pathForResource:@"conversions" 
        ofType:@"plist"
    ];
    NSDictionary *dictionary = [[NSDictionary alloc]
        initWithContentsOfFile:plistPath
    ];

    // Store conversions
    for(NSDictionary *dict in [dictionary valueForKey:@"Conversions"]) {
        [self.conversions arrayByAddingObject:[dict valueForKey:@"name"]];
        [self.categories arrayByAddingObject:[dict valueForKey:@"conversions"]];
    }
    [dictionary release];

    [self loadIntoPicker:0];
}

- (void)loadIntoPicker:(NSInteger)index {       
        // Set the current category
        NSArray *category = [self.categories objectAtIndex:index];

        for (NSDictionary *conversion in category) {
            [self.typesFrom arrayByAddingObject:[conversion valueForKey:@"type"]];
            [self.typesTo arrayByAddingObject:[conversion valueForKey:@"type"]];
            [self.descriptions arrayByAddingObject:[conversion valueForKey:@"description"]];
            [self.multipliers arrayByAddingObject:[conversion valueForKey:@"multiplier"]];
        }

        [picker selectRow:0 inComponent:1 animated:YES];
        [picker selectRow:0 inComponent:2 animated:YES];
        [picker reloadComponent:1];
        [picker reloadComponent:2];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if ( component == kCategoryComponent )
        return [self.conversions count];
    else 
        return [self.typesFrom count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if ( component == kCategoryComponent ) 
        return [self.conversions objectAtIndex:row];
    else if ( component == kConvertFromComponent )
        return [self.typesFrom objectAtIndex:row];
    else    
        return [self.typesTo objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if ( component == kCategoryComponent ) {
        if ( row >= 0 )
            [self loadIntoPicker:row];
    }
}

The plist I’m using:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Conversions</key>
    <array>
        <dict>
            <key>name</key>
            <string>Speed</string>
            <key>conversions</key>
            <array>
                <dict>
                    <key>type</key>
                    <string>mph</string>
                    <key>description</key>
                    <string>mile/hour</string>
                    <key>multiplier</key>
                    <integer>1</integer>
                </dict>
                <dict>
                    <key>type</key>
                    <string>ft/s</string>
                    <key>description</key>
                    <string>foot/second</string>
                    <key>multiplier</key>
                    <real>1.466667</real>
                </dict>
                <dict>
                    <key>type</key>
                    <string>km/h</string>
                    <key>description</key>
                    <string>kilometer/hour</string>
                    <key>multiplier</key>
                    <real>1.609344</real>
                </dict>
                <dict>
                    <key>type</key>
                    <string>m/s</string>
                    <key>description</key>
                    <string>meter/second</string>
                    <key>multiplier</key>
                    <real>0.44704</real>
                </dict>
            </array>
        </dict>
        <dict>
            <key>name</key>
            <string>Distance</string>
            <key>conversions</key>
            <array>
                <dict>
                    <key>type</key>
                    <string>ft</string>
                    <key>description</key>
                    <string>feet</string>
                    <key>multiplier</key>
                    <integer>1</integer>
                </dict>
                <dict>
                    <key>type</key>
                    <string>yd</string>
                    <key>description</key>
                    <string>yard</string>
                    <key>multiplier</key>
                    <real>0.3333333</real>
                </dict>
                <dict>
                    <key>type</key>
                    <string>mi</string>
                    <key>description</key>
                    <string>mile</string>
                    <key>multiplier</key>
                    <real>0.0001894</real>
                </dict>
                <dict>
                    <key>type</key>
                    <string>in</string>
                    <key>description</key>
                    <string>inch</string>
                    <key>multiplier</key>
                    <integer>12</integer>
                </dict>
                <dict>
                    <key>type</key>
                    <string>m</string>
                    <key>description</key>
                    <string>meter</string>
                    <key>multiplier</key>
                    <real>0.3048</real>
                </dict>
                <dict>
                    <key>type</key>
                    <string>km</string>
                    <key>description</key>
                    <string>kilometer</string>
                    <key>multiplier</key>
                    <real>0.0003048</real>
                </dict>
                <dict>
                    <key>type</key>
                    <string>cm</string>
                    <key>description</key>
                    <string>centimeter</string>
                    <key>multiplier</key>
                    <real>30.48</real>
                </dict>
            </array>
        </dict>
        <dict>
            <key>name</key>
            <string>Volume</string>
            <key>conversions</key>
            <array>
                <dict>
                    <key>type</key>
                    <string>ft^3</string>
                    <key>description</key>
                    <string>cubic feet</string>
                    <key>multiplier</key>
                    <integer>1</integer>
                </dict>
                <dict>
                    <key>type</key>
                    <string>liter</string>
                    <key>description</key>
                    <string>liter</string>
                    <key>multiplier</key>
                    <real>28.31685</real>
                </dict>
                <dict>
                    <key>type</key>
                    <string>acre ft</string>
                    <key>description</key>
                    <string>acre foot</string>
                    <key>multiplier</key>
                    <real>2.3e-05</real>
                </dict>
                <dict>
                    <key>type</key>
                    <string>barrel</string>
                    <key>description</key>
                    <string>barrel [US, liquid]</string>
                    <key>multiplier</key>
                    <real>0.2374768</real>
                </dict>
                <dict>
                    <key>type</key>
                    <string>gallon</string>
                    <key>description</key>
                    <string>gallon [US, liquid]</string>
                    <key>multiplier</key>
                    <real>29.92208</real>
                </dict>
                <dict>
                    <key>type</key>
                    <string>quart</string>
                    <key>description</key>
                    <string>quart [US, liquid]</string>
                    <key>multiplier</key>
                    <real>29.92208</real>
                </dict>
            </array>
        </dict>
    </array>
</dict>
</plist>
  • 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-05-27T08:31:28+00:00Added an answer on May 27, 2026 at 8:31 am

    It looks like your arrays are not being initialised or filled properly.

    arrayByAddingObject: returns the new array containing the added object, but you are not using the return value of those statements.

    If your arrays are NSMutableArray properties, try this code:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
    
        // Grab information from the plist
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *plistPath = [bundle 
            pathForResource:@"conversions" 
            ofType:@"plist"
        ];
        NSDictionary *dictionary = [[NSDictionary alloc]
            initWithContentsOfFile:plistPath
        ];
    
        self.conversions = [NSMutableArray arrayWithCapacity:0];
        self.categories = [NSMutableArray arrayWithCapacity:0];
    
        // Store conversions
        for(NSDictionary *dict in [dictionary valueForKey:@"Conversions"]) {
            [self.conversions addObject:[dict valueForKey:@"name"]];
            [self.categories addObject:[dict valueForKey:@"conversions"]];
        }
        [dictionary release];
    
        [self loadIntoPicker:0];
    }
    

    If they are of NSArray type, you can modify the code like so:

       - (void)viewDidLoad
        {
            [super viewDidLoad];
            // Do any additional setup after loading the view from its nib.
    
            // Grab information from the plist
            NSBundle *bundle = [NSBundle mainBundle];
            NSString *plistPath = [bundle 
                pathForResource:@"conversions" 
                ofType:@"plist"
            ];
            NSDictionary *dictionary = [[NSDictionary alloc]
                initWithContentsOfFile:plistPath
            ];
    
            NSMutableArray *tempConversions = [NSMutableArray arrayWithCapacity:0];
            NSMutableArray *tempCategories = [NSMutableArray arrayWithCapacity:0];
    
            // Store conversions
            for(NSDictionary *dict in [dictionary valueForKey:@"Conversions"]) {
                [tempConversions addObject:[dict valueForKey:@"name"]];
                [tempCategories addObject:[dict valueForKey:@"conversions"]];
            }
            [dictionary release];
    
            self.conversions = tempConversions;
            self.categories = tempCategories;
    
            [self loadIntoPicker:0];
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.