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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:57:56+00:00 2026-06-14T20:57:56+00:00

So I have created a simple UITableViewController that I push onto the NavigationController .

  • 0

So I have created a simple UITableViewController that I push onto the NavigationController.
I created an initWithPList method that reads a plist and stores the values into an NSMutableDictionary in the items @property in a class called Settings.

The NSMutableDictionary is populated correctly in the initWithStyle method. But in viewDidLoad, the NSMutableDictionary items @property of the Settings NSObject is nil.

I am not sure what I am doing wrong any ideas????

Here is some code:

Showing the ViewController:

TestViewController *settingsViewController = [[TestViewController alloc] initWithStyle:UITableViewStyleGrouped]; 
[[self navigationController] pushViewController:settingsViewController animated:YES]

Initializing the TestViewController:

- (id)initWithStyle:(UITableViewStyle)style{
    
       if (self = [super initWithStyle:style]) {
                
           // Init settings property here
           settings = [[Settings alloc] initWithPList];
           // settings.items has a count of 5 here....which is correct
       }
       return self;
  }

viewDidLoad for the TestViewController

- (void)viewDidLoad
{
     [super viewDidLoad];
      
      // Check settings object here to see if it still has items

      // settings.items is nil here for somereason??

      NSLog(@"%i", [settings.items count]); // now it's nil here?
    
 }

The Settings NSObject:

#import <Foundation/Foundation.h>

@interface Settings : NSObject {

    NSMutableDictionary *items;
    NSString *path;
}

@property(nonatomic, retain) NSMutableDictionary *items;
@property(nonatomic, retain) NSString *path;

-(id)initWithPList;

@end

A snippet of the @implementation:

@synthesize items;
@synthesize path;

-(id) initWithPList {

    path = [[self documentsDirectory]stringByAppendingPathComponent:@"Settings.plist"];

    if(![[NSFileManager defaultManager]fileExistsAtPath:path])
    {
        [[NSFileManager defaultManager]copyItemAtPath:[[NSBundle mainBundle]pathForResource:@"Settings" ofType:@"plist"] toPath:path error:nil];
    }

    items = [NSMutableDictionary dictionaryWithContentsOfFile:path];   
    return self;  
}
  • 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-14T20:57:57+00:00Added an answer on June 14, 2026 at 8:57 pm
    @synthesize items;
    

    By synthesizing this way, the backing ivar for the property is named items. So when you say

        items = [NSMutableDictionary dictionaryWithContentsOfFile:path];
    

    you’re assigning directly to the ivar. In pre-ARC manual memory management, any direct manipulation of the ivar has no connection with “retain” property. Retain/release at the ivar level is totally up to you.

    Now because you’re creating a dictionary by calling +dictionaryWithContentsOfFile:, the dictionary is autoreleased. So you’ve given a persistent variable (the items ivar) a transient object. Poof, it’s gone!

    The solution is to take ownership of the dictionary. Some convenience methods don’t have a non-autorelease equivalent, so we’d have to add a retain to them. But in this case, there is an equivalent initializer:

        items = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
    

    You have ownership. Problem solved. (This also avoids adding anything to the autorelease pool.)

    Extra:
    It’s still confusingly dangerous for the ivar have the same name as the property. It’s easy to get lulled into thinking that you’re getting the attributes of the property whenever you see items. First, let’s get rid of the explicit declaration of ivars. They’re not needed for properties.

    @interface Settings : NSObject
    
    @property(nonatomic, retain) NSMutableDictionary *items;
    @property(nonatomic, retain) NSString *path;
    
    - (id)initWithPList;
    
    @end
    

    Apple’s convention is to prefix ivars with an underscore. If you’re using Xcode 4.5, simply omit the @synthesize statement entirely. For earlier Xcode, change the synthesize to use a slightly different name for the ivar:

    @synthesize items = _items;
    

    Then initWithPlist can say

        _items = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
    

    The underscore serves as a reminder: “This is the ivar! Memory management is your problem!” (And so, you dutifully release it in the dealloc method.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created simple async controllers that call into async methods that then call
I have created a simple WordPress plugin that automatically sets my new sites up
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created a simple chat server that is driven by client polling. Clients
I have created a simple search field that will ajax in relevant search results
I have a simple problem. I created a custom UITableViewCell that includes a UISwitch
I have created this simple JavaScript code that allows a user to click on
i have created a simple database for inserting the list of data into my
I have created a simple API for a Rails application using token-based-authentication that supports
I have created simple web service for my website that generates some json based

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.