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

Realm meetup Japan #22

Realm meetup Japan #22

Realm Objective-C/Swift 2.4-2.7
Realm Functions
Realm events at WWDC

9bf923e39671cde83584e3e926296c13?s=128

Kishikawa Katsumi

May 30, 2017
Tweet

Transcript

  1. Realm meetup #22 kk@realm.io

  2. #realm_jp kk@realm.io

  3. Katsumi Kishikawa Realm Inc. kk@realm.io

  4. Recent Updates • Realm Objective-C/Swift 2.7.0 (was 2.4.3) • Realm

    Java 3.3.1 (was 3.0.0) • Realm JS 1.3.1 (was 1.1.1) • Realm .NET 1.4.0 (1.1.1) kk@realm.io
  5. Realm .NET 1.3.0 kk@realm.io

  6. Realm for Universal Windows Platform kk@realm.io

  7. Realm Objective-C/Swift 2.7.0 kk@realm.io

  8. Realm Objective-C/Swift 2.4.4 • ಉظ͞ΕͨRealmͷΞΫηεݖͷঢ়ଶΛҰཡͰ͖ΔPermission Realm ͱSyncPermissionΫϥεͷ௥Ճ (Deprecated) kk@realm.io

  9. Permission RealmʗSyncPermission kk@realm.io let permissionRealm = try! user.permissionRealm() let permissions

    = permissionRealm.objects(SyncPermission.self).filter("...") for permission in permissions { print(permission.path) print(permission.userId) print(permission.mayRead) print(permission.mayWrite) print(permission.mayManage) }
  10. Realm Objective-C/Swift 2.5.0 • μΠΞΫϦςΟΧϧϚʔΫΛແࢹ͢Δݕࡧ • ϑΝΠϧϑΥʔϚοτͷΞοϓάϨʔυ ⚠ kk@realm.io

  11. μΠΞΫϦςΟΧϧϚʔΫɺେจࣈখจࣈΛແࢹͯ͠ݕࡧ kk@realm.io realm.objects(VideoGame.self).filter("name == %@", “Pokémon") realm.objects(VideoGame.self).filter("name ==[d] %@", “Pokemon")

    realm.objects(VideoGame.self).filter("name ==[cd] %@", “pokemon")
  12. Realm Objective-C/Swift 2.6.0 • ඇಉظʹRealmΛ։͘ϝιου`asyncOpen()`ͷ௥Ճ • ىಈ࣌ʹඞཁʹԠͯࣗ͡ಈతʹίϯύΫγϣϯΛߦ͏Φϓγϣϯɺ `shouldCompactOnLaunch`ͷ௥Ճ kk@realm.io

  13. `asyncOpen()`: ඇಉظʹRealmΛ։͘ kk@realm.io let config = Realm.Configuration(schemaVersion: 9, migrationBlock: {

    migration, oldSchemaVersion in // σʔλྔ͕ଟ͘ɺϚΠάϨʔγϣϯʹ͕͔͔࣌ؒΓͦ͏ͳͱ͖ }) Realm.asyncOpen(configuration: config) { realm, error in if let realm = realm { // ׬ྃͨ͠ΒίʔϧόοΫ͕ݺ͹Εɺ࢖༻ՄೳͳRealmΠϯελϯε͕౉͞ΕΔ } else if let error = error { // Τϥʔ͕ൃੜͨ͠৔߹ } } // ϚΠάϨʔγϣϯ͸όοΫάϥ΢ϯυεϨουͰ࣮ߦ͞ΕΔͷͰɺ׬ྃΛ଴ͨͣʹ࣍ͷॲཧʹਐΊΔ ...
  14. `asyncOpen()`: ඇಉظʹRealmΛ։͘ kk@realm.io let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL:

    realmURL)) Realm.asyncOpen(configuration: config) { realm, error in if let realm = realm { // ಉظ͞ΕͨRealmͷ৔߹ɺ͢΂ͯͷσʔλ͕μ΢ϯϩʔυ͞Εͨ࣌఺ͰίʔϧόοΫ͕ݺ͹ΕΔ } else if let error = error { // RealmϑΝΠϧͷΦʔϓϯʹࣦഊɺ͋Δ͍͸σʔλͷμ΢ϯϩʔυʹࣦഊ } } ...
  15. `shouldCompactOnLaunch`: ىಈ࣌ʹίϯύΫγϣϯΛ࣮ߦ kk@realm.io let config = Realm.Configuration(shouldCompactOnLaunch: { totalBytes, usedBytes

    in // totalBytes - ࣮ࡍͷϑΝΠϧ༰ྔʢσʔλྖҬ + ۭ͖ྖҬʣ // usedBytes - ࣮ࡍͷϑΝΠϧ༰ྔͷ͏ͪσʔλྖҬͷαΠζ // totalBytes͕100MBΛ௒͑ɺ͔ۭ͖ͭྖҬ͕50%Ҏ্ͳΒίϯύΫγϣϯΛ࣮ߦ͢Δ let oneHundredMB = 100 * 1024 * 1024 return (totalBytes > oneHundredMB) && (Double(usedBytes) / Double(totalBytes)) < 0.5 }) do { // ઃఆͨ͠৚݅ʹ౰ͯ͸·Δ৔߹ɺ࠷ॳʹRealmϑΝΠϧΛ։͘ࡍʹίϯύΫγϣϯ͕࣮ߦ͞ΕΔ let realm = try Realm(configuration: config) } catch { // Τϥʔॲཧ }
  16. Realm Objective-C/Swift 2.7.0 • Reachability APIʹΑΓಉظ͞ΕͨRealmͷ࠶઀ଓ·Ͱͷ࣌ؒΛ࠷ద Խ • Realm Object

    ServerͷRealmೝূͷύεϫʔυมߋ • ಉظ͞ΕͨRealmͷΞΫηεݖΛΑΓ؆୯ʹѻ͑Δ৽͍͠API kk@realm.io
  17. Password change APi kk@realm.io user.changePassword("...") { (error) in if let

    error = error { ... return } ... }
  18. New Permission APi kk@realm.io let permissionChange = SyncPermissionChange(realmURL: realmURL, userID:

    anotherUserID, mayRead: true, mayWrite: true, mayManage: false) let managementRealm = try! user.managementRealm() try! managementRealm.write { managementRealm.add(permissionChange) } // Wait for server response token = permissionChange.addNotificationBlock { _ in switch permissionChange.status { case .notProcessed: break // handle case case .success: break // handle case case .error: break // handle case } print(permissionChange.statusMessage) // contains error or informational message } Before:
  19. New Permission APi kk@realm.io let permission = SyncPermissionValue(realmPath: realmPath, userID:

    anotherUserID, accessLevel: .write) user.applyPermission(permission) { error in if let error = error { // handle error return } // success! } After:
  20. New Permission APi kk@realm.io // Retrieving permissions user.retrievePermissions { permissions,

    error in if let error = error { // handle error return } // success! access permissions } After:
  21. Realm Functions kk@realm.io

  22. Realm Functions • αʔόʔαΠυͷεΫϦϓτ࣮ߦ؀ڥ • Realm Mobile PlatformͷWebμογϡϘʔυ͔ΒRealmͷมߋΛτϦΨʔʹ࣮ ߦ͞ΕΔ೚ҙͷίʔυΛهड़Ͱ͖Δ •

    Realm Mobile PlatformͷશΤσΟγϣϯͰར༻Մೳ • ※Developer Edition͸̏ͭ·Ͱͷ੍ݶ͋Γ • ϕʔλ൛ • ࣮ߦ࣌ؒɾίʔυαΠζͳͲDeveloper Editionʹ͓͚Δొ࿥਺Ҏ֎ͷ੍ݶͳ ͠ʢࠓͷͱ͜Ζʣ • ೚ҙͷ֎෦API΍Node.jsϥΠϒϥϦΛ࢖༻Մೳ kk@realm.io
  23. Realm Functions kk@realm.io

  24. Realm Functions kk@realm.io

  25. Realm Functions kk@realm.io

  26. Realm Functions kk@realm.io console.log("Starting function"); // add your initialization code

    here module.exports = function(changeEvent) { // event handler code goes here console.log("Changes in realm at:", changeEvent.path); var realm = changeEvent.realm; for (var className in changeEvent.changes) { var changes = changeEvent.changes[className]; var objects = realm.objects(className); ... } console.log(""); };
  27. Realm Functions kk@realm.io var i, pos; for (i = 0;

    i < changes.insertions.length; i++) { pos = changes.insertions[i]; var inserted = objects[pos] ... } for (i = 0; i < changes.modifications.length; i++) { pos = changes.modifications[i]; var modified = objects[pos] ... } for (i = 0; i < changes.deletions.length; i++) { pos = changes.deletions[i]; var deleted = objects[pos] ... }
  28. Realm Functions kk@realm.io

  29. Demo kk@realm.io

  30. New RMP Dashboard kk@realm.io

  31. Integrated Realm Browser kk@realm.io

  32. kk@realm.io

  33. Log Viewer Improved kk@realm.io

  34. kk@realm.io

  35. WWDC at Realm kk@realm.io http://news.realm.io/news/wwdc-2017/

  36. Questions? Katsuma Kishikawa kk@realm.io www.realm.io/jp @k_katsumi

  37. Ξϯέʔτ bit.ly/RealmJP_22 kk@realm.io