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 trialKunakorn Puntawong
3,016 PointsWhy do I need arrayWithArray method in this case
The instructor wrote:
_playlistArtists = [NSArray arrayWithArray: [playDictionary objectForKey:kArtist]];
The [playDIctionary objectForKey:kArtist] already returns an array. So, why do I still need arrayWithArray method ? why can't I do something like this:
_playlistArtists =[playDictionary objectForKey:kArtist];
1 Answer
Madhav Sharma
4,081 PointsYour question is a very good example in understanding 'pointers'. If we set it equal like how you did, we would set the pointer '_playlistArtists' to the same address contained in 'playlistDictionary' (which is contained in property 'library' of the object 'musicLibrary') . Because we declared the property '_playlistArtists' as a strong reference, it will still work because the pointers created in the method won't be there after execution.
But I guess, it is just more intuitive to allocate a separate, new array which is a copy of the last one as the permanent one we will keep to store our data.
Darean Wong
Courses Plus Student 4,186 PointsDarean Wong
Courses Plus Student 4,186 PointsI have this question too. Can someone please let us know why?