Why don't objective-c array parameters use a colon?

I am currently studying some of the objective-c from the great ranch guide. I understand that methods with multiple parameters use colons to separate each parameter, but reading about creating arrays, I found this piece of code:

 NSArray *dateList = [NSArray arrayWithObjects:now, tomorrow, yesterday, nil];

This confused me, because I thought that the parameters of the objective-c method should be preceded by a part of the method name along with a colon. Can someone explain this to me?

+4
source share
2 answers

This is an exception to the rule; this is commonly called the variational method. If you look at the definition in NSArray.h:

+ (instancetype)arrayWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION;

, , nil ( sentinel).

, , . NSObject,

- (id)performSelector:(SEL)aSelector withObject:(id)object1;
- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2;

( ).

+6

, .

Objective-C - Apple Developer:

+ (instancetype nonnull)arrayWithObjects:(ObjectType nonnull)firstObj, ...;

, , !

+4

All Articles