turnkey ======= a rubymotion utility for extending [NSCoder protocols](https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/Protocols/NSCoding_Protocol/Reference/Reference.html) and saving objects to [NSUserDefaults](https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSUserDefaults_Class/Reference/Reference.html) ### Installation ```bash $ gem install turnkey ``` ### Setup Add this line to your Rakefile: ```ruby require 'turnkey' ``` or, if you're using Bundler, to your Gemfile: ```ruby gem 'turnkey' ``` ### Usage ####Saving objects to disk To save a custom object to disk, just pass the object, along with the key you'll use to retrieve it, to Turnkey's `archive` method: ```ruby song = Song.new.tap{|s| s.title = "In Bloom"; s.artist = "Nirvana"} => # Turnkey.archive(song, "Nirvana Song") => true ``` To retrieve it, call `unarchive` ```ruby Turnkey.unarchive("Nirvana Song") => # ``` ####Arrays/Hashes You can also pass Arrays or Hashes of objects to `archive`: #####Array ```ruby song_array = [] => [] 5.times {|i| song_array << Song.new.tap{|s| s.title = "Song ##{i + 1}"}} => 5 Turnkey.archive(song_array, "List of Songs") => true Turnkey.unarchive("List of Songs") => [#, #, #, #, #] ``` #####Hash ```ruby hash = {songs: song_array, song: Song.new.tap{|s| s.title = "7 and 7 Is"}} Turnkey.archive(hash, "Song Dictionary") => true Turnkey.unarchive("Song Dictionary") => {"songs"=>[#, #, #, #, #], "song"=>#} ``` ####Relations Turnkey's `archive` can take objects with references to other custom objects, i.e ```ruby a = Artist.new.tap{|artist| artist.name = "Stone Roses"} s = Song.new{|song| song.title = "Made of Stone"; song.artist = a} Turnkey.archive(song, "song with artist") ``` The NSCoder Protocols will be extended to both the object being archived and any objects it holds references to ; ) Rock.