14jbella
14jbella

Reputation: 535

What is the difference between setObject:forKey setObject:forKeyedSubscript

Is there any difference between the methods setObject:forKey and setObject:forKeyedSubscript?

I am using an Objective-C NSMutableArray. Both seem to function the same way to me.

Upvotes: 2

Views: 1588

Answers (2)

Léo Natan
Léo Natan

Reputation: 57050

setObject:forKeyedSubscript: and setObject:atIndexedSubscript: are used for mutable collection subscripting methods, introduced with the Objective C Literals.

setObject:forKeyedSubscript: is used for dictionary-styled mutable collections. You should not use it with array-style collections.

More info here.

Upvotes: 5

gnasher729
gnasher729

Reputation: 52592

Documentation says:

"This method is identical to setObject:forKey:".

Upvotes: 0

Related Questions