Can I initialize an NSArray in Singleton with specific values ​​(e.g. const)?

I have a Singleton, and I would like to declare an NSArray, but I would like to initialize it with 5 (incoherent) integers.

Now it is declared in the interface .h> Interface, .h> @property and .m> @synthesize.

How can i do this? Thanks.

0
objective-c iphone xcode
source share
1 answer

In your singleton -init method, just create and initialize it there:

- (id)init { _array = [[NSArray arrayWithObjects:[NSNumber numberWithInt:5], [NSNumber numberWithInt:50], [NSNumber numberWithInt:3.72], [NSNumber numberWithInt:5], [NSNumber numberWithInt:96], nil] retain]; return self; } 
+1
source share

All Articles