iPhone Persistence For Mere Mortals

33
Code and Slides: http://thillerson.googlecode.com iPhone Persistence For Mere Mortals Tony Hillerson Software Architect Tuesday, March 3, 2009

description

iPhone Persistence talk I gave at 360|iDev in Spring 2008.

Transcript of iPhone Persistence For Mere Mortals

Page 1: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

iPhone Persistence For Mere Mortals Tony Hillerson

Software Architect

Tuesday, March 3, 2009

Page 2: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence

Tuesday, March 3, 2009

Page 3: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

... or it means saving stuff.

Persistence

Tuesday, March 3, 2009

Page 4: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

BTW: I’m a n00b

Persistence: Disclaimer

Tuesday, March 3, 2009

Page 5: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Savin’ stuff on ur foneYour options

Tuesday, March 3, 2009

Page 6: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Settings SQLiteFilesystemThe Internets

Persistence: Options

Tuesday, March 3, 2009

Page 7: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Settings SQLiteFilesystemThe Internets

Persistence: Options

Tuesday, March 3, 2009

Page 8: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Our Sweet App

Tuesday, March 3, 2009

Page 9: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Sweet Codeshttp://github.com/thillerson/grocery_getter/

Download

Tuesday, March 3, 2009

Page 10: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: SettingsYours or Apple’s?

Tuesday, March 3, 2009

Page 11: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Apple’s => Settings.bundle

Persistence: Settings

Yours => Roll your ownBoth end up in NSUserDefaults

Tuesday, March 3, 2009

Page 12: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Settings

Can be one of:NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary

Tuesday, March 3, 2009

Page 13: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

[NSUserDefaults standardUserDefaults];

Persistence: Settings

NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];

[settings setBool:YESforKey:@"shouldSortAfterComplete"];

[NSUserDefaults resetStandardUserDefaults];BOOL on = [settings boolForKey:@"shouldSortAfterComplete"];

Tuesday, March 3, 2009

Page 14: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: SQLiteIt’s small, but it’s feisty!

Tuesday, March 3, 2009

Page 15: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: SQLite

YO DAWG I HERD YOU LIEK DATA...

Tuesday, March 3, 2009

Page 16: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: SQLite

SQLite - Embedded Relational Database written in C

Tuesday, March 3, 2009

Page 17: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: SQLite

Embedded Relational Database

written in C

Tuesday, March 3, 2009

Page 18: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

CocoaTouch:Terra Firma

SQLite:Hic Draconae

Sunt

Tuesday, March 3, 2009

Page 19: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: SQLite

3 Takes on our Sweet App:• SQLite C API• fmdb + fmdb-migration-

manager• Aptiva’s ActiveRecord

Tuesday, March 3, 2009

Page 20: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: SQLite

SQL C API:http://www.sqlite.org/c3ref/funclist.html

Tuesday, March 3, 2009

Page 21: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: SQLite

• fmdb - Thin Wrapper around SQLite• fmdb-migration-manager - Rails-style

migrations using fmdb

• http://code.google.com/p/"ycode/• http://github.com/mocra/fmdb-

migration-manager/

Tuesday, March 3, 2009

Page 22: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: SQLite

• Aptiva’s ActiveRecordIn software engineering, the active record pattern is a design pattern frequently found in software that stores its data in relational databases. It was named by Martin Fowler in his book Patterns of Enterprise Application Architecture.- http://en.wikipedia.org/wiki/Active_record_pattern

http://github.com/aptiva/activerecord/

Tuesday, March 3, 2009

Page 23: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: SQLite

Quick! To the CODES!

Tuesday, March 3, 2009

Page 24: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: A Few PointsTake two, they’re small!

Tuesday, March 3, 2009

Page 25: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Tips

Consider how your settings will be used

Tuesday, March 3, 2009

Page 26: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Tips

A database is an implementation detail

Tuesday, March 3, 2009

Page 27: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Tips

Encapsulation is your friend

Tuesday, March 3, 2009

Page 28: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Tips

Don’t forget to move your database

Tuesday, March 3, 2009

Page 29: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Tips

SQLite write speed is constrained by transactions

Tuesday, March 3, 2009

Page 30: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Tips

SQLite uses duck-typing

Tuesday, March 3, 2009

Page 31: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Tips

FMDB: executeQuery != executeUpdate

Tuesday, March 3, 2009

Page 32: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Tips

RTFS

Tuesday, March 3, 2009

Page 33: iPhone Persistence For Mere Mortals

Code and Slides:http://thillerson.googlecode.com

Persistence: Thank you!

slideshare.com/thillersongithub.com/thillerson twitter.com/thillersonbrightkite.com/thillerson

EffectiveUI.com

Tony HillersonSoftware Architect

Tuesday, March 3, 2009