2

As I was reading I saw this:

static NSString *randomNounList[3];

does that make an array of NSString pointers called randomNouns?

2 Answers 2

3

Yes, that makes an array of 3 pointers to NSString and you can freely use it as normal array.

Just remember that unlike objective-c containers plain arrays do not retain their elements and you have to maintain all memory management issues yourself (e.g. retain strings to make sure then won't get deallocated prematurely and release them when you don't need them).

Sign up to request clarification or add additional context in comments.

Comments

1

It is neither an NSArray nor an NSString — it's a plain C array of pointers to NSStrings. It's not an object; it's just a block of memory with space for three pointers.

Using a C array with Cocoa objects like this is usually (but not always) a bad idea IMO. C arrays are troublesome enough in plain C. When you add in the more complicated memory management semantics of Cocoa, it can be tricky to manage everything correctly unless you wrap the array in an NSArray-like interface — and if you're doing that, why aren't you just using an NSArray?

1 Comment

hehe, nice point. well you know thanks a lot for sharing your idea. i am learning programming therefor i come across a variety of authors with different code selection style. and to be hounest i thought its more neat to use the above code. Thanks to you i now know i should avoid them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.