Voices property


#1

Hi,
I have a question about the implementation of the TableView.

I first tried to declare the _voices Array as a property:

@property (assign) NSArray *_voices;

I took over the rest of the code exactly. This would give me many errors. Why? How would I do the implementation with the @property correct? Why do I need a declaration in the {} brackets at all? Isn’t that unnecessary because I can do it with the @property thing?


#2

DaPhil,

In the modern Objective-C runtime you can skip declaring the instance variable; creating an @property and @synthesize-ing it is enough to tell the compiler to create it for you. Did you also add a line “@synthesize _voices;” in your implementation file? (for more on properties, check out page 124 in Chapter 7)

Additionally, because this is a pointer to an NSArray, you want the property to be “strong”, not “assign”.

If you choose to use an underscore prefix on instance variable names, usually this prefix is not carried through to the public property name. So in your header file you would say:

and then in the implementation file:

This will create an instance variable called _voices.

Hope this helps,

Adam


#3

Yes thanks, I had to declare it as strong! That was the mistake.