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

Introducing CloudKit

A77456b262557e22986345f6d0555c58?s=47 nakajijapan
August 20, 2014

Introducing CloudKit

Introducing CloudKit

A77456b262557e22986345f6d0555c58?s=128

nakajijapan

August 20, 2014
Tweet

Transcript

  1. QPUBUPUJQT !OBLBKJKBQBO *OUSPEVDJOH $MPVE,JU

  2. !OBLBKJKBQBO 4PGUXBSF&OHJOFFS (.01&1"#0JOD J048FC.BD

  3. ৺ྶಈըΞϓϦ΋͏Ұ౓͝ཡ͍ͨͩ͜͏ IUUQPXLSJOGPNPWJF ৺ྶࣸਅΞϓϦ͓Θ͔Γ͍͚ͨͩͨͩΖ͏͔ IUUQPXLSJOGP J1IPOFήʔϜதౡਗ਼૟ہ GSVTUSBUJPONF IUUQWBDVVNOBLBKJKBQBOOFU IUUQGSVTUSBUJPONF

  4. !OBLBKJKBQBO 4PGUXBSF&OHJOFFS (.01&1"#0JOD J048FC.BD w 88%$͍ͬͯདྷ·ͨ͠ w ࠷ۙ͸झຯͰ.BD049ΞϓϦ΍ͬͯ·͢ w "7'PVOEBUJPOपΓΛझຯͰௐ΂ͯ·͢

  5. $MPVE,JU

  6. "HFOEB w 8IBUJT$MPVE,JU  w 4JNQMF$36% w ໰୊ w ཁௐࠪ

    w 3FWJFX $MPVE,JU
  7. 8IBUJT$MPVE,JU w J$MPVETFSWFS΁ͷσʔλసૹΛ؅ཧ w J$MPVEBDDPVOU w .BD049ͱJ04ͷαϙʔτ w 1VCMJD"SFBʹσʔλΛอଘͰ͖Δ $MPVE,JU

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

    3FDPSE*EFOUJpFST w 3FGFSFODFT w "TTFUT $MPVE,JU
  9. 3FDPSET w $,3FDPSE w 4USVDUVSFE%BUB w 8SBQTLFZWBMVFQBJST w 3FDPSE5ZQF w

    +VTUJOUJNFTDIFNB w .FUBEBUB $MPVE,JU
  10. 4JNQMF$36% $MPVE,JU

  11. $SFBUF $MPVE,JU func saveRecord( record: CKRecord!, completionHandler: ((CKRecord!, NSError!) ->

    Void)!) $,%BUBCBTF
  12. $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") } } )
  13. %FMFUF $MPVE,JU func deleteRecordWithID( recordID: CKRecordID!, completionHandler: ((CKRecordID!, NSError!) ->

    Void)!) $,%BUBCBTF
  14. %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") } } )
  15. 6QEBUF $MPVE,JU func saveRecord( record: CKRecord!, completionHandler: ((CKRecord!, NSError!) ->

    Void)!) $,%BUBCBTF GVODGFUDI3FDPSE8JUI*%  SFDPSE*%$,3FDPSE*%  DPNQMFUJPO)BOEMFS $,3FDPSE /4&SSPS 7PJE 
  16. 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") } } ) } )
  17. 3FBE $MPVE,JU w $,2VFSZ w 3FDPSE5ZQF w /41SFEJDBUF w /44PSU%FTDSJQUPST

  18. 3FBE $MPVE,JU w $,2VFSZ w 3FDPSE5ZQF w /41SFEJDBUF w /44PSU%FTDSJQUPST

    MPHJDBMDPOEJUJPO TPSU
  19. 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
  20. 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) } } } )
  21. ໰୊ $MPVE,JU

  22. ໰୊ $MPVE,JU 5BCMF7JFXͰQBHJOHͯ͠Έ͍ͨ

  23. ໰୊ w ϖʔδ৘ใ͍࣋ͬͯΔΘ͚Ͱ͸ͳ͍ w 0GGTFU-JNJUͰͰ͖ΔΘ͚Ͱ΋ͳ͍ $MPVE,JU 5BCMF7JFXͰQBHJOHͯ͠Έ͍ͨ

  24. $PSF%BUB $MPVE,JU let request = NSFetchRequest(entityName: "Item") request.fetchOffset = 0

    request.fetchLimit = 10 Ͱ͸ύοͱࢥ͍ͭ͘
  25. ໰୊ $MPVE,JU 5BCMF7JFXͰQBHJOHͯ͠Έ͍ͨ αϯϓϧίʔυ͕ͳ͔ͬͨͷͰυΩϡϝϯτͱʹ ΒΊͬͯࣗ͜͠෼ͳΓʹ࣮૷ͯ͠Έ·ͨ͠ɻ

  26. ໰୊ $MPVE,JU 5BCMF7JFXͰQBHJOHͯ͠Έ͍ͨ WBSRVFSZ$PNQMFUJPO#MPDL $,2VFSZ$VSTPS /4&SSPS 7PJE  DVSTPS "$,2VFSZ$VSTPSPCKFDUUIBUJOEJDBUFTUIFSFBSFNPSFSFTVMUTUPGFUDIPS

    OJMJGUIFSFTVMUTQBSBNFUFSDPOUBJOTBMMPGUIFSFNBJOJOHTFBSDISFTVMUT 6TFUIFQSPWJEFEPCKFDUUPJOJUJBMJ[FBOFXRVFSZPQFSBUJPOPCKFDUXIFO ZPVBSFSFBEZUPSFUSJFWFUIFOFYUCBUDIPGSFTVMUT $,2VFSZ0QFSBUJPO
  27. ໰୊ 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ͯ͠Έ͍ͨ
  28. ໰୊ $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)
  29. ໰୊ $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)
  30. ໰୊ $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)
  31. ཁௐࠪ $MPVE,JU

  32. ཁௐࠪ $MPVE,JU w $,3FDPSE;POF w $,4VCTDSJQUJPO w 0GqJOF$BDIF w &SSPS)BOEMJOH

  33. 3FWJFX $MPVE,JU w ιʔγϟϧܥαʔϏεʹ͸͋·Γ޲͍ͯͳ͍ʁ w σʔλΦϒδΣΫτͷ୅ସͰ͸ͳ͍ɺJ$MPVE4FSWFS΁ͷ σʔλసૹΛ؅ཧ͢ΔิࠤతͳαʔϏεΛఏڙ͢Δ w όοΫΞοϓػೳ͕ͳ͍ w

    ߏங͕؆୯͗͢Δ w ΫϦοΫ͚ͩͰ࣮૷͢Δ४උ͕Ͱ͖͕͋Δ w .BD049༻ͷΞϓϦΛ࡞੒͢Δ৔߹͸ผ్ܖ໿͕ɻɻɻ IUUQTEFWFMPQFSBQQMFDPNMJCSBSZQSFSFMFBTFNBDEPDVNFOUBUJPO$MPVE,JU3FGFSFODF$MPVE,JU@'SBNFXPSL@3FGFSFODFJOEFYIUNMBQQMF@SFGEPD VJE51
  34. 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
  35. UIBOLT