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
Nephi Shields
420 PointsUIApplication and opening links in mobile Safari
Hello people of the Internet! I have a question about opening URLs in mobile safari. When I was trying to figure out how to so it on my own I tried this line in didSelectRowAtIndexPath:
[[UIApplication sharedApplication] openURL: blogPost.url];
Which worked just fine but when I watched Opening a Web Page in Safari Amit wrote:
UIApplication *application = [UIApplication sharedApplication];
[application openURL:blogPost.url];
Is there any reason to write it one way or the other? Does it matter?
1 Answer
Thomas Anthony
iOS Development Techdegree Student 22,352 PointsThere is no fundamental difference between the two examples you proposed. Amit when through the trouble of storing a reference to the sharedApplication instance before sending the openURL: message –which is fine. In contrast, your expression is written 'inline', as in, written on a single line (without storing any references). Either one of those statements are valid.
Just as a bit of friendly advice, I suggest you get yourself a little more familiar with the Objective-C language. You can sign up to codeschool and go through their Try Objective-C course for free. Then come back and review the iOS Foundations Deep Dive here at Treehouse. Happy coding!
Nephi Shields
420 PointsNephi Shields
420 PointsThanks for the answer and advice!
Thomas Anthony
iOS Development Techdegree Student 22,352 PointsThomas Anthony
iOS Development Techdegree Student 22,352 PointsAnytime! If you are truly passionate about iOS development, I encourage you to stick with it. iOS has one of the greatest ecosystems of any mobile operating system and provides a rich and rewarding experience.