How do you pass objects between View Controllers in Objective-C?

Posted by editor on Stack Overflow See other posts from Stack Overflow or by editor
Published on 2010-05-05T03:43:03Z Indexed on 2010/05/05 3:48 UTC
Read the original article Hit count: 117

Filed under:
|
|

I've been trudging through some code for two days trying to figure out why I couldn't fetch a global NSMutableArray variable I declared in the .h and implemented in .m and set in a the viewDidLoad function.

It finally dawned on me: there's no such thing as a global variable in Objective-C, at least not in the PHP sense I've come to know. I didn't ever really read the XCode error warnings, but there it was, even if not quite plain English: "Instance variable 'blah' accessed in class method."

My question: What am I supposed to do now? I've got two View Controllers that need to access a central NSMutableDictionary I generate from a JSON file via URL. It's basically an extended menu for all my Table View drill downs, and I'd like to have couple other "global" (non-static) variables.

Do I have to grab the JSON each time I want to generate this NSMutableDictionary or is there some way to set it once and access it from various classes via #import? Do I have to write data to a file, or is there another way people usually do this?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about xcode