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 trialMisho Milicevic
5,597 PointsNavigating Docs
How does one even make sense of navigating the documentation? I can see you guys do it in the videos but my attempts to make any sense whatsoever from searching the documentation leaves with the feeling of wanting to throw my computer out the window! Sorry, but it's true.
I switched from learning objective-c to Swift and now am going back to objective-c to grasp those concepts again. I'm lost! And my simple attempt to rediscover how to simply find the correct syntax to assign a value from an array to a string has left me very frustrated. I scour the pages, from one thing to another, reading jargon and snippets I don't understand and nowhere after 15 pages have I found the simple line of code that shows the syntax.
I thought this is how it goes:
NSString *bookTitle = self.booksArray[objectAtIndex:2];
... But apparently it's not
Please help, as I am seriously about to throw my laptop out the window. And the help I most would appreciate is how best to search the Docs without wasting hours of my time on such simple problems.
NSArray *booksArray = [NSArray arrayWithObjects: @"Hamlet", @"King Lear", @"Othello", @"Macbeth", nil];
NSString *bookTitle = self.booksArray[objectAtIndex:2];
1 Answer
Stone Preston
42,016 PointsobjectAtIndex is a method (its not used like a subscript value).
method calls generally look like this:
[objectToCallMethodOn methodName:argument];
we want to call the objectAtIndexMethod on the booksArray and assign the 3rd item to a new string variable. note this is a just a local variable, not a property, so you dont use self.
NSArray *booksArray = [NSArray arrayWithObjects: @"Hamlet", @"King Lear", @"Othello", @"Macbeth", nil];
NSString *bookTitle = [booksArray objectAtIndex:2];
Navigating documentation and learning how to read it is an art that takes practice and patience. the best way to learn how to use it is to use it more ; ). That is true of many things in programming (and anything really). Practice makes perfect
Misho Milicevic
5,597 PointsMisho Milicevic
5,597 PointsThank you Stone, I really appreciate it! I'll try to be more patient as I do realize learning programming requires a lot of it. I just get frustrated given the very limited time I have to practice and learn the art of programming and when I get stuck, wasting all my free time to solve the simplest issues I once knew before I forgot them, I do loose my cool sometimes. So thanks again!
Stone Preston
42,016 PointsStone Preston
42,016 Pointsthat time is not wasted, so dont feel bad/discouraged. Debugging code and researching your problems and issues is very important to know how to do. Just because you arent writing code does not mean you arent learning and advancing your knowledge of programming. There are many ways to do that, and debugging/researching your issues is probably one of the best
Misho Milicevic
5,597 PointsMisho Milicevic
5,597 PointsWise words my friend, thanks again for reminding me of that as well