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

  • Home
  • SEARCH
  • 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 6181619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:03:30+00:00 2026-05-24T01:03:30+00:00

I have a project on iPhone with iOS4. A instance variable of app delegate

  • 0

I have a project on iPhone with iOS4.

A instance variable of app delegate is a dictionary with global readonly data loaded from a plist when app starts.

CalculatorAppDelegate.h

 #import <UIKit/UIKit.h>
 @class MainViewController;

 @interface CalculatorAppDelegate : NSObject <UIApplicationDelegate> {
 NSDictionary *RGBSpacesDictionary;
 }

 @property (nonatomic, retain) IBOutlet UIWindow *window;
 @property (nonatomic, retain, readonly) NSDictionary *RGBSpacesDictionary;
 @property (nonatomic, retain) IBOutlet MainViewController *mainViewController;
 @end

CalculatorAppDelegate.m

 #import "CalculatorAppDelegate.h"
 #import "MainViewController.h"
 @implementation CalculatorAppDelegate

 @synthesize mainViewController=_mainViewController;
 @synthesize RGBSpacesDictionary;

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
     // load plist 
     NSString* plistPath1 = [[NSBundle mainBundle] pathForResource:@"RGBSpaces" ofType:@"plist"];
     RGBSpacesDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath1];

    etc.
 }

Then in MainViewController i am able to successfully reading the dictionary in viewDidLoad

MainViewController.h

 @class CalculatorAppDelegate;
 @interface MainViewController : UIViewController <FlipsideViewControllerDelegate> {
 CalculatorAppDelegate *appDelegate;
 }
 @property (nonatomic, retain) CalculatorAppDelegate *appDelegate;

 etc.
 }

MainViewCOntroller.m

 #import "CalculatorAppDelegate.h"
 @implementation MainViewController
 @synthesize appDelegate;

 - (void)viewDidLoad
 {
     [super viewDidLoad];
     appDelegate = [[UIApplication sharedApplication] delegate]; 
     RGBSpacesCount = (int) [appDelegate.RGBSpacesDictionary count];
 }

In viewDidLoad it is all OK, I can read my dictionary as appDelegate.REGSpaceDictionary.

The problem is with another method of MainVievController called when a button is pressed

- (IBAction) RGBSpaceButtonPressed {
     NSLog(@"appDelegate.RGBSpacesDictionary %@", appDelegate.RGBSpacesDictionary);

 etc.
 }

At this time calling the dictionary (for example with a NSLog) return in a crash.

Can someone help me? Thank you.

  • 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-24T01:03:31+00:00Added an answer on May 24, 2026 at 1:03 am

    In this line

    RGBSpacesDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath1];
    

    you are assigning an autoreleased object straight to the ivar so there is no guarantee how long it will stay around for. You should be assigning a non autoreleased object or going through the setter

    // Going through the setter
    self.RGBSpacesDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath1];
    
    // OR
    // Non assigning a non autoreleased object
    RGBSpacesDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath1];
    

    To use the setter you would have to redeclare the property in an extension at the top of the app delegate’s .m file like this

    @interface CalculatorAppDelegate ()
    @property (nonatomic, retain, readwrite) NSDictionary *RGBSpacesDictionary;
    @end
    
    ...
    
    The rest of your implementation
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work on a project for iPhone iOS4 with Xcode 4. My app uses
I work on a project for iPhone iOS4 with Xcode. From MainViewController I want
I have upgraded my XCode to versio 3.2.3 to support iOS4 on my iphone
In my iPhone app, I have this button, that opens a webcal:// URL in
I have an Xcode iPhone project with 3 configurations, debug, release and adhoc. What
I have a 3.1 xcode project that has been running my app just fine
I am developing an iphone project in which I have to use Walrus S3
I have been trying to encrypt/ decrypt a sqlite database in my iPhone project.
Very new to Iphone development here, I have a project which is successfully building
If I have a project that was written for iphone and a project written

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.