Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

BID 7: Chapter 9, Page 274 - API vs. Property Naming Conflict

I'm a little confused regarding the description given for the conflict between the variable titled favorites in the header file and the favorites property defined in the same:

"Note that we're declaring a property named favorites, of type NSMutableArray.  In our header file, we just declared a method called favorites that returns an NSArray.  Since declaring a property also typically declares the existence of a getter and a setter, won't this lead to a conflict?"

The description for the potential conflict seems to indicate that the definition of favorites in the interface section will clash with the methods generated by the property statement for favorites in the class extension of the implementation file.  However as I understand it, defining a property using the property key word will generate methods with the names getFavorties and setFavorites, along with an instance variable named _favorites.  Thus I'm not really clear on where this potential clash would occur as noted, but there must be something I'm missing else the explanation in the book wouldn't have been provided.

Another question i have is: if it is the mutability of the array that we are concerned with here, could we not have used the copy keyword in our property definition for the favorites array and accomplished the same goal?

Thanks in advance for your assistance.

Here is the text from the book:

#import <Foundation/Foundation.h>

@interface BIDFavoritesList : NSObject

-(NSArray *)favorites;

...


#import "BIDFavoritesList.h"

@interface BIDFavoritesList ()

@property (strong, nonatomic) NSMutableArray *favorites;

Comments

  • I believe now I understand the conflict.  In my post above, I stated that the getter is named getFavorites, when in reality the getter is simply named favorites (duh!); thus the collision.
Sign In or Register to comment.