$30 off During Our Annual Pro Sale. View Details »

iOS Overview

Chris Schepman
June 14, 2012
200

iOS Overview

Chris Schepman

June 14, 2012
Tweet

Transcript

  1. An iOS Overview or ... “Oh shit. I just got

    put an iOS project! Help?” Thursday, June 14, 12
  2. Quick Resources • Stanford CS193p • cs193p.stanford.edu • WWDC Videos

    • Apple Docs (In Xcode!) Thursday, June 14, 12
  3. Objective-C • It is weird. • But you know C

    right? • err.. How about Javascript? • .. SmallTalk? Thursday, June 14, 12
  4. “Message Passing” wtf? [activityIndicator startAnimating]; //verbosity cell.textLabel.text = [[songList objectAtIndex:indexPath.row]

    title]; //this won’t work! not for methods activityIndicator.startAnimating(); //properties are happier though! activityIndicator.color = [UIColor ...]; Thursday, June 14, 12
  5. Blocks! • So good. [UIView animateWithDuration:.5 animations:^{ self.quoteLabel.alpha = 0;

    self.quoteWeb.alpha = 0; self.leftQuote.alpha = 0; self.rightQuote.alpha = 0; if (!isBookmarked) { self.bookmarkImage.alpha = 0; } } completion:^(BOOL finished) { //... }]; Thursday, June 14, 12
  6. Make it pretty! [UIView animateWithDuration:.5 animations:^{ //any property in here!

    }]; //UIViewAnimationOptionCurveEaseInOut //UIViewAnimationOptionCurveLinear Thursday, June 14, 12
  7. DATA • Core Data • Massive • Fast (speed) •

    Slow (development) • Not Flexible • Very Good Documentation Thursday, June 14, 12
  8. DATA - Cont’d • NSUserDefaults • Key Value Store •

    Fast (development) • Slow (speed) • Not Real Queries • Good Enough? Thursday, June 14, 12
  9. DATA - Cont’d • Write [[NSUserDefaults standardUserDefaults] setObject:self.bookmarks forKey:@"bookmarks"]; [[NSUserDefaults

    standardUserDefaults] synchronize]; • Read self.bookmarks = [[[NSUserDefaults standardUserDefaults] objectForKey:@"bookmarks"] mutableCopy]; Thursday, June 14, 12
  10. DATA - Cont’d • Other Options! • FMDB • https://github.com/ccgus/fmdb

    • Objective-C sqlite wrapper • Parse • https://parse.com Thursday, June 14, 12
  11. Text Layout • UILabel doesn’t have a lineHeight property •

    UIWebView to the rescue? quoteHTML = @"<html><body style=\"background-color: transparent; font-family: Georgia; line-height: 40px; font-size:18pt; text-shadow: 0px 1px #FFF; text-align: center;\">%@</body></html>"; Thursday, June 14, 12
  12. Must Know L’s - Cont’d //some function calls this! [self

    loadTweetInBackground]; - (void)loadTweetInBackground { [tweetSpinner startAnimating]; latestTweet.text = @""; [NSThread detachNewThreadSelector:@selector(loadTweet) toTarget:self withObject:nil]; } - (void)loadTweet { ! NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [NSThread sleepForTimeInterval:1]; ! NSString *urlString = @"http://api.twitter.com/1/statuses/user_timeline.json? count=1&screen_name=babykettenOR"; ! NSURL *url = [NSURL URLWithString:urlString]; ! NSString *jsonString = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; ! if (jsonString != nil) { id jsonValue = [jsonString JSONValue]; self.tweet = [[jsonValue objectAtIndex:0] valueForKey:@"text"]; } else { self.tweet = @"Can't reach the internetz! Sing pretty!"; } ! [self performSelectorOnMainThread:@selector(didFinishLoadingTweet) withObject:nil waitUntilDone:NO]; ! [jsonString release]; ! [pool release]; } - (void)didFinishLoadingTweet { ! [tweetSpinner stopAnimating]; latestTweet.text = tweet; } Thursday, June 14, 12
  13. Must Know L’s - Cont’d NSURL *url = [NSURL URLWithString:@"https://gdata.youtube.com/feeds/api/standardfeeds/top_rated?

    alt=json?time=this_week"]; NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url]; [urlRequest setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"]; MBJSONRequest *jsonRequest = [[[MBJSONRequest alloc] init] autorelease]; [jsonRequest performJSONRequest:urlRequest completionHandler:^(id responseJSON, NSError *error) { if (error != nil) { NSLog(@"Error requesting top-rated videos: %@", error); } else { NSArray *videos = [[responseJSON objectForKey:@"feed"] objectForKey:@"entry"]; for (NSDictionary *videoInfo in videos) { NSString *title = [[videoInfo objectForKey:@"title"] objectForKey:@"$t"]; NSString *author = [[[[videoInfo objectForKey:@"author"] objectAtIndex:0] objectForKey:@"name"] objectForKey:@"$t"]; NSLog(@"'%@' by %@", title, author); } } }]; Thursday, June 14, 12
  14. Must Know L’s - Cont’d • JSONKit • https://github.com/johnezang/JSONKit •

    faster than binary .plist! • Nineveh.gl (http://nineveh.gl/) • Import super common models • 3D framework worth exploring (young) Thursday, June 14, 12
  15. Must Know L’s - Cont’d • http://iosboilerplate.com/ • MBProgressHUD /

    SVProgressHUD • AFNetworking • Built-in browser • Lots more Thursday, June 14, 12
  16. Totally Screwed? • You know the Web! • UIWebView •

    Titanium/PhoneGap • Clutch - https://clutch.io/ • Mobile Safari! Thursday, June 14, 12