meetup uikit programming
TRANSCRIPT
![Page 1: Meetup uikit programming](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/1.jpg)
UIKit Programming(and some network stuff too)
João Prado MaiaIpanema Labs, LLC
http://ipanemalabs.com
![Page 2: Meetup uikit programming](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/2.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/3.jpg)
Tonight’s session
•Hands on
•Lots of code to go through
•Ask questions at any time!
![Page 4: Meetup uikit programming](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/4.jpg)
Table views
•Standard classes:
• UINavigationController
• UIViewController
• UITableViewController
•Goal: build a simple app with a drill down interface.
![Page 5: Meetup uikit programming](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/5.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/6.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/7.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/8.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/9.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/10.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/11.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/12.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022062404/554a4841b4c9055a408b5481/html5/thumbnails/13.jpg)
Q&A
•Any questions?