how to declare static variables in objective c

Hey I am new to objective c development. Can anyone tell me how to make a class like:

public class test
{

public static final String tableName = "asdfas";    
public static final String id_Column = "_id";
public static final String Z_ENT_Column = "Z_ENT";

}

which we can access without making the instance, like:

String abc = test.tableName;

Answers


If I am right you want to create constants (because you use final over there in question.) for obj-c. You can use extern for that.

Do something like this.

1.) Create new Obj-c class named Constants.

2.) In .h file write something

extern const NSString *SERVICE_URL;

3.) In .m file write

NSString * SERVICE_URL=@"http://something/services";

4.) Now Use them in your view controller just import Constants.h

5.) Access directly as NSString *url=SERVICE_URL;


And if you don't want to create constants and simply want to use static in obj-c then I afraid to say that in Obj-c you can only use static in .m (Implementation) file. And they can be accessed directly without prefixing the Class Name. e.g.

static NSString *url=@"something";

I hope this what you need.


Need Your Help

Core Data background sorting

sorting core-data background nsmanagedobjectcontext fetched-property

I have a Department entity which has a one-to-many relationship to an Employee entity. During runtime, for each Department object I want to maintain a sorted array of Employee objects (sorted acco...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.