Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics (Retired) Foundation Framework NSArray

Abdulaziz Al-Zahrani
Abdulaziz Al-Zahrani
3,469 Points

Why I couldn't do it that way !?

Hi

when I want to make a regular Array I can use both ways

1st

NSArray *test = [[NSArray alloc]initWithObjects: ..., nil];

2nd

NSArray *test = @[@"d",@"o",@"o"];

However in the second type of array Mutablearaay I can use the second method and it prints the objects ,but I can't remove the object by its index. I can remove it by following the old method of initializing . I want a deep explain why that happened. Thank you :)

1 Answer

Holger Liesegang
Holger Liesegang
50,595 Points

Hi Abdulaziz Al-Zahrani ,

you might want to have a look at NSMutableArray and under "Removing Objects" there are several methods how to remove an object out of the index like e. g. - (void)removeObjectAtIndex:(NSUInteger)index.