How do I create a global variable using Objectvie-C in iPhone?
I'm the beginner in iPhone software development, and I'm creating a HTTP request using the SOAP XML parsing method.
I was creating a variable soapResult
for storing the received http data. I want to use the soapResult
value into another class.
How can I access that value. I was going to make it a global variable but i don't know how to create and u开发者_开发问答se it?
Also if that method is wrong then how should I implement it?
Generally, singletons are preferred over global variables.
I found this article useful on a similar matter: Cocoa with Love: Singletons, AppDelegates and top-level data
I suggest you to use something like Registry pattern. Just create class Registry with static methods and static properties. It is better way to controll all shared stuff in your app
Global vars are not preferred in objective-c, but if you want to use, this approach works well.
精彩评论