How do I use (instancetype)arrayWithObjects:(id)?

138 views Asked by At

I am trying to use this iOS function

  • +(instancetype)arrayWithObjects:(id)

I believe I passed an array into it, but I cannot figure out how to access that array and I do not understand HOW to use this. I have spent several hours trying to figure it out ... PLEASE help me!

+ (instancetype)arrayWithObjects:(id)[@"Starcraft", @"League of Legends", @"Starcraft 2", @"World of Warcraft",
@"The Sims", @"Icewind Dale", @"Shadowbane", @"Grand Theft Auto 3", @"Pac Man", @"Astroids",
@"Grand Theft Auto 4", @"Grand Theft Auto 5", @"MineCraft", @"Mass Effect", @"Mass Effect 2",
@"Mass Effect 3", @"Dragon Age", @"The Sims 2", @"The Sims 3", @"Rockband", @"Rockband 2",
@"Rockband 3", @"Dragon Age 2", @"The Witcher", @"The Witcher 2", @"Plants vs Zombies",
nil]
{
    return [[[self class] alloc] init];
}
1

There are 1 answers

6
ahwulf On

This is what you really want if you want an entire array of objects instead of an array with a single array in it which is what you had originally.

NSArray* array = [NSArray arrayWithObjects:@"Starcraft", @"League of Legends", @"Starcraft 2", @"World of Warcraft",
@"The Sims", @"Icewind Dale", @"Shadowbane", @"Grand Theft Auto 3", @"Pac Man", @"Astroids",
@"Grand Theft Auto 4", @"Grand Theft Auto 5", @"MineCraft", @"Mass Effect", @"Mass Effect 2",
@"Mass Effect 3", @"Dragon Age", @"The Sims 2", @"The Sims 3", @"Rockband", @"Rockband 2",
@"Rockband 3", @"Dragon Age 2", @"The Witcher", @"The Witcher 2", @"Plants vs Zombies",
nil];

It creates an NSArray at runtime of the given strings ending in nil to indicate the end.