Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing CloudKit

nakajijapan
August 20, 2014

Introducing CloudKit

Introducing CloudKit

nakajijapan

August 20, 2014
Tweet

More Decks by nakajijapan

Other Decks in Technology

Transcript

  1. $MPVE,JU0CKFDUT w $POUBJOFST w %BUBCBTFT w 3FDPSET w 3FDPSE;POFT w

    3FDPSE*EFOUJpFST w 3FGFSFODFT w "TTFUT $MPVE,JU
  2. $SFBUF $MPVE,JU self.container.publicCloudDatabase.saveRecord( record, completionHandler: { (record:CKRecord!, error:NSError!) -> Void

    in if error { println("An error occurred in \(error.description)") abort() } else { println("Successfully Created record") } } )
  3. %FMFUF $MPVE,JU self.container.publicCloudDatabase.deleteRecordWithID( record.recordID, completionHandler: { (recordID:CKRecordID!, error:NSError!) -> Void

    in if error { println("An error occured in \(error.description)") abort() } else { println("Successfully deleted record") } } )
  4. 6QEBUF $MPVE,JU func saveRecord( record: CKRecord!, completionHandler: ((CKRecord!, NSError!) ->

    Void)!) $,%BUBCBTF GVODGFUDI3FDPSE8JUI*%  SFDPSE*%$,3FDPSE*%  DPNQMFUJPO)BOEMFS $,3FDPSE /4&SSPS 7PJE 
  5. 6QEBUF $MPVE,JU self.cloudManager.publicDatabase.fetchRecordWithID( model.recordID, completionHandler: { (record:CKRecord!, error:NSError!) -> Void

    in record.setObject("nakajijapan" , forKey: "screen_name") self.cloudManager.container.publicCloudDatabase.saveRecord( record, completionHandler: { (rec:CKRecord!, err:NSError!) -> Void in if err == nil { println("Successfully deleted record") } } ) } )
  6. 3FBE $MPVE,JU let predicate = NSPredicate(format: "title <> ''", argumentArray:

    nil) /41SFEJDBUF query.sortDescriptors = [NSSortDescriptor(key: "title", ascending: false)] /44PSU%FTDSJQUPST GVODQFSGPSN2VFSZ  RVFSZ$,2VFSZ  JO;POF8JUI*%[POF*%$,3FDPSE;POF*%  DPNQMFUJPO)BOEMFS <"OZ0CKFDU> /4&SSPS 7PJE   $,3FDPSE  $,%BUBCBTF
  7. 3FBE $MPVE,JU let predicate = NSPredicate(value: true) let query:CKQuery =

    CKQuery(recordType: "Items", predicate: predicate) self.container.publicDatabase.performQuery( query, inZoneWithID: nil, { (results:[AnyObject]!, error:NSError!) -> Void in if !error { ! for record in results as [CKRecord]! { println(record) } } } )
  8. ໰୊ $MPVE,JU 5BCMF7JFXͰQBHJOHͯ͠Έ͍ͨ WBSRVFSZ$PNQMFUJPO#MPDL $,2VFSZ$VSTPS /4&SSPS 7PJE  DVSTPS "$,2VFSZ$VSTPSPCKFDUUIBUJOEJDBUFTUIFSFBSFNPSFSFTVMUTUPGFUDIPS

    OJMJGUIFSFTVMUTQBSBNFUFSDPOUBJOTBMMPGUIFSFNBJOJOHTFBSDISFTVMUT 6TFUIFQSPWJEFEPCKFDUUPJOJUJBMJ[FBOFXRVFSZPQFSBUJPOPCKFDUXIFO ZPVBSFSFBEZUPSFUSJFWFUIFOFYUCBUDIPGSFTVMUT $,2VFSZ0QFSBUJPO
  9. ໰୊ w $,2VFSZ0QFSBUJPOΛར༻ͨ͠GFUDIํ๏ w SFDPSE'FUDIFE#MPDL w RVFSZ$PNQMFUJPO#MPDL w SFTVMUT-JNJU w

    $,2VFSZ$VSTPS w OJM࣍ͷϖʔδ͋Γ w OJM࣍ͷϖʔδͳ͠ $MPVE,JU 5BCMF7JFXͰQBHJOHͯ͠Έ͍ͨ
  10. ໰୊ $MPVE,JU let query:CKQuery = CKQuery(recordType: "Items", predicate: predicate) !

    (snip) ! var queryOperation:CKQueryOperation if self.cursor != nil { queryOperation = CKQueryOperation(cursor: self.cursor) } else { queryOperation = CKQueryOperation(query: query) } ! queryOperation.resultsLimit = 10 ! queryOperation.recordFetchedBlock = {(record:CKRecord!) -> Void in self.items.append(record) } ! queryOperation.queryCompletionBlock = { (cursor:CKQueryCursor!, error:NSError!) -> Void in // snip self.cursor = cursor } ! self.container.publicDatabase.addOperation(queryOperation)
  11. ໰୊ $MPVE,JU let query:CKQuery = CKQuery(recordType: "Items", predicate: predicate) !

    (snip) ! var queryOperation:CKQueryOperation if self.cursor != nil { queryOperation = CKQueryOperation(cursor: self.cursor) } else { queryOperation = CKQueryOperation(query: query) } ! queryOperation.resultsLimit = 10 ! queryOperation.recordFetchedBlock = {(record:CKRecord!) -> Void in self.items.append(record) } ! queryOperation.queryCompletionBlock = { (cursor:CKQueryCursor!, error:NSError!) -> Void in // snip self.cursor = cursor } ! self.container.publicDatabase.addOperation(queryOperation)
  12. ໰୊ $MPVE,JU let query:CKQuery = CKQuery(recordType: "Items", predicate: predicate) !

    (snip) ! var queryOperation:CKQueryOperation if self.cursor != nil { queryOperation = CKQueryOperation(cursor: self.cursor) } else { queryOperation = CKQueryOperation(query: query) } ! queryOperation.resultsLimit = 10 ! queryOperation.recordFetchedBlock = {(record:CKRecord!) -> Void in self.items.append(record) } ! queryOperation.queryCompletionBlock = { (cursor:CKQueryCursor!, error:NSError!) -> Void in // snip self.cursor = cursor } ! self.container.publicDatabase.addOperation(queryOperation)
  13. 3FWJFX $MPVE,JU w ιʔγϟϧܥαʔϏεʹ͸͋·Γ޲͍ͯͳ͍ʁ w σʔλΦϒδΣΫτͷ୅ସͰ͸ͳ͍ɺJ$MPVE4FSWFS΁ͷ σʔλసૹΛ؅ཧ͢ΔิࠤతͳαʔϏεΛఏڙ͢Δ w όοΫΞοϓػೳ͕ͳ͍ w

    ߏங͕؆୯͗͢Δ w ΫϦοΫ͚ͩͰ࣮૷͢Δ४උ͕Ͱ͖͕͋Δ w .BD049༻ͷΞϓϦΛ࡞੒͢Δ৔߹͸ผ్ܖ໿͕ɻɻɻ IUUQTEFWFMPQFSBQQMFDPNMJCSBSZQSFSFMFBTFNBDEPDVNFOUBUJPO$MPVE,JU3FGFSFODF$MPVE,JU@'SBNFXPSL@3FGFSFODFJOEFYIUNMBQQMF@SFGEPD VJE51
  14. 3FGFSFODF $MPVE,JU w $MPVE,JU'SBNFXPSL3FGFSFODF w IUUQTEFWFMPQFSBQQMFDPNMJCSBSZQSFSFMFBTFNBDEPDVNFOUBUJPO$MPVE,JU 3FGFSFODF$MPVE,JU@'SBNFXPSL@3FGFSFODFJOEFYIUNMBQQMF@SFGEPDVJE 51  w

    *OUSPEVDJOH$MPVE,JU w 4FTTJPO w IUUQTEFWFMPQFSBQQMFDPNWJEFPTXXED w "EWBODFE$MPVE,JU w 4FTTJPO w IUUQTEFWFMPQFSBQQMFDPNWJEFPTXXED