开发者

Reading an object from another class

开发者 https://www.devze.com 2023-03-22 16:16 出处:网络
I am using XCode 4.0.2 for a iOS4 project. When my app starts, the application didFinishLaunchingWithOptions method in the application delegate loads a NSDictionary form a plist:

I am using XCode 4.0.2 for a iOS4 project.

When my app starts, the application didFinishLaunchingWithOptions method in the application delegate loads a NSDictionary form a plist:

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"RGBSpaces" ofType:@"plist"];
RGBSpacesDictionary = [NSDicti开发者_JAVA技巧onary dictionaryWithContentsOfFile:plistPath];

The NSDictionary is readonly. How can I read one or more elements of NSDictionary from an arbitrary class?

Thank you


UIApplication *appDelegate = [[UIApplication sharedApplication] delegate];

And then you can use appDelegate to access its properties including dictionaries.


Rather then doing with Appdelegate the simpler option would be create a class for that of type NSObject and you update and get value just by importing that class wherever required.Another option would be NSUserDefaults.Depends on the requirements which to use.

0

精彩评论

暂无评论...
验证码 换一张
取 消