Declaring collection accessor methods in Objective-C necessary?

I've got a quickie today. Say I have a class called BSDHistoryManager. It's a simple state history recorder like in a web browser (aka a History object [window.history]). Here are simplified examples of the .h/m files:


@interface BSDHistoryManager : NSObject

@property (nonatomic, copy) NSArray *states;



@implementation BSDHistoryManager {
    NSMutableArray *_states;

- (NSArray *)states
    return _states.copy;

- (void)setStates:(NSArray *)states
    if ( [states isEqualToArray:_states] )
    _states = states.mutableCopy;


As you can see, I have a standard mutable collection on the inside which is copied when accessed with the getter so the internals don't get messed up. At this point, I want to add some public accessor methods like -addState:, -removeState:, etc. For example, I like to make my own accessors like this:

- (void)addState:(BSDState *)state;
- (void)insertState:(BSDState *)state atIndex:(NSUInteger)index;

However, I want to define KVC methods, too. You know, the ones that look like this:

- (void)addStatesObject:(id)object;
- (void)insertObject:(id)object inStatesAtIndex:(NSUInteger)index;

Now I have both, and that's cool, but I want my class interface to be nice and clean, so it's easier to read and understand. My question is: when implementing the KVC accessor patterns, do I need to declare those methods or do I get KVC-compliance "for free" by just implementing the methods? Or a better question is: do I even need to implement the KVC methods if I make my own custom-named ones?

Hopefully this makes sense, but if not, I'll try to explain it a little better. Thanks for reading!


Need Your Help

Base64 String to Image

php rest base64

I hava a rest-webservice and i want to upload the image as a base64 string and decode it on my webserver using php.

Are there any Stackless Python like projects for other languages (Java, Lisp, Haskell, Go etc)

python haskell compiler-construction lisp interpreter

Well thats the question. Are there any projects for other languages which try to imitate what stackless python is doing for python?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.