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 trialVlatko .
2,526 PointsWhich of these styles is more commonly used?
After going through a few of the Foundation Framework objects, there are two ways to write the values for objects. Example:
First Method
NSArray *foo = [[NSArray alloc] initWithObjects: @"f", @"o", @"o", nil];
Second Method
NSArray *foo = @[@"f", @"o", @"o"];
I would much more prefer to use the second method when writing code because it is a lot easier and faster to write, but would there be any downside to only using this method? Is there a time where the first method (alloc, init) would be better to use?
1 Answer
Stone Preston
42,016 PointsI use literals a lot more because its faster. if there is a literal way I use it because its a lot faster than having to call alloc and init all the time
Vlatko .
2,526 PointsVlatko .
2,526 PointsSo, by using a literal, it basically allocates the memory and initializes objects automatically without the need to type it all out?
Stone Preston
42,016 PointsStone Preston
42,016 Pointsyep thats exactly what it does.
Vlatko .
2,526 PointsVlatko .
2,526 PointsThank you!
Stone Preston
42,016 PointsStone Preston
42,016 Pointsno problem, you can read all about literals here