Objective-C: How Can I Access String Variable As a Global?

后端 未结 4 1400
你的背包
你的背包 2020-12-20 04:31

I am new to iPhone development. I want to access a string variable in all the class methods, and I want to access that string globally. How can I do this?

Please hel

4条回答
  •  我在风中等你
    2020-12-20 05:04

    The preferred methods for creating a global variable are:

    1. Create a singleton class that stores the variables as an attributes.
    2. Create a class that has class methods that return the variables. Put the class interface in the universal header so all classes in the project inherit it.

    The big advantage of method (2) is that it is encapsulated and portable. Need to use classes that use the global in another project? Just move the class with the variables along with them.

提交回复
热议问题