Declare static member variables like Java's in Objective-C

class, java, objective-c, static

Solution

It looks like you want to create constants (since you are using `final` in your question). In Objective-C, you can use `extern` for that.

Do something like this:

1) Create a new Objective-C class named Constants.

2) In the header (.h) file:

extern const NSString *SERVICE_URL;

3) In the implementation (.m) file:

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

4) Add `#import "Constants.h"` to any class where you want to use it

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

If you don't want to create constants and simply want to use `static` in Objective-C, unfortunately you can only use `static` in the implementation (.m) file. And they can be accessed directly without prefixing the Class Name.

For example:

static NSString *url = @"something";

I hope this helps.

Problem

How can I make an Objective-C class with class-level variables like this Java class? ``` 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"; } ``` I want to access them without making an instance, like: ``` String abc = test.tableName; ```

Original source