Fogmeister
Fogmeister

Reputation: 77641

- (void)add<NAME>Object: function

If you define a property for a mutable array...

@property (nonatomic, strong) NSMutableArray *objects;

Then you start to write the function... - (void)addObje... then auto complete will finish then name and give you...

- (void)addObjectsObject:(<#object-type#> *)object
{
}

My question is, how should I be using this function?

Do I have to call

[self addObjectsObject:someObject];

or can I just do

[self.objects addObject:someObject];

i.e. will the NSMutableArray property know that I've overridden the add object function and use my defined function to add it?

Upvotes: 0

Views: 44

Answers (1)

Anoop Vaidya
Anoop Vaidya

Reputation: 46543

You need to use [self addObjectsObject:someObject];.

[self.objects addObject:someObject]; will invoke the NSMutableArray's method directly on the property.

EDIT:

Some more information:

[self addObjectsObject: someObject];//calls the method - (void)addObjectsObject:
[self.objects addObject: someObject];//calls the property directly

If you want to override your method, you need to sub-class or you can make a category, but do not use same method name to override an existing category.

Upvotes: 2

Related Questions