meetup uikit programming

13
UIKit Programming (and some network stuff too) João Prado Maia Ipanema Labs, LLC http://ipanemalabs.com

Upload: joaopmaia

Post on 06-May-2015

6.284 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Meetup uikit programming

UIKit Programming(and some network stuff too)

João Prado MaiaIpanema Labs, LLC

http://ipanemalabs.com

Page 2: Meetup uikit programming

Who?•Web programmer by day, iOS

developer by night.

•Consultant on iOS development projects. Contact me at http://ipanemalabs.com

•Few apps on App Store since 2008.

•Personal site at http://pessoal.org

Page 3: Meetup uikit programming

Tonight’s session

•Hands on

•Lots of code to go through

•Ask questions at any time!

Page 4: Meetup uikit programming

Table views

•Standard classes:

• UINavigationController

• UIViewController

• UITableViewController

•Goal: build a simple app with a drill down interface.

Page 5: Meetup uikit programming

Saving data to SQLite

•FMDB!

• http://code.google.com/p/flycode/source/browse/trunk/fmdb

• Open source wrapper on top of SQLite.

• Actively maintained; easy to work with.

•Goal: change previous example to load information from a SQLite database.

Page 6: Meetup uikit programming

Dealing with an API

•ASIHTTPRequest

• http://allseeing-i.com/ASIHTTPRequest/

• Much more convenient than NSURLConnection.

• Open source; very easy to use.

•Goal: modify previous example to load data from an API dynamically.

Page 7: Meetup uikit programming

ASIHTTPRequest• Advanced features available to you in an easy

to use wrapper:

• Download data to memory or directly to file

• Easy to upload files through POST

• Automatic progress indicators for downloads/uploads

• Asynchronous/Synchronous requests and persistent connections

• etc

• Good documentation with lots of examples

Page 8: Meetup uikit programming

ASIHTTPRequest (2)

- (IBAction)grabURL:(id)sender

{

NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

[request startSynchronous];

NSError *error = [request error];

if (!error) {

NSString *response = [request responseString];

}

}

Page 9: Meetup uikit programming

ASIHTTPRequest (3)

- (IBAction)grabURLInBackground:(id)sender

{

NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

[request setDelegate:self];

[request startAsynchronous];

}

- (void)requestFinished:(ASIHTTPRequest *)request

{

// Use when fetching text data

NSString *responseString = [request responseString];

// Use when fetching binary data

NSData *responseData = [request responseData];

}

- (void)requestFailed:(ASIHTTPRequest *)request

{

NSError *error = [request error];

}

Page 10: Meetup uikit programming

JSON• JSON - JavaScript Object Notation

• Serialization format much less verbose than XML

• Perfect for web services that need to return information for mobile clients

• iOS library: json-framework

• http://code.google.com/p/json-framework/

• Open source (BSD) library

Page 11: Meetup uikit programming

JSON (2)

•Serialized hash/dictionary:{“key1”: “value1”, “key2”: “value2”}

•Serialized array:[“value1”, “value2”, “value3”]

•Mixed object (array of dictionaries):

[{“name”: “Joao”, “ssn”:”12345678”}, {“name”:”Barry”, “ssn”:”98765432”}]

Page 12: Meetup uikit programming

JSON parsing example

NSArray *list;

NSString *jsonString = @"[\"Meetup\", \"is\", \"cool\"]";

list = [jsonString JSONValue];

NSLog(@"first entry: %@", [list objectAtIndex:0]);

NSLog(@"second entry: %@", [list objectAtIndex:1]);

NSLog(@"third entry: %@", [list objectAtIndex:2]);

[json release];

Page 13: Meetup uikit programming

Q&A

•Any questions?