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

Realm Mobile Platform overview and demo

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.
Avatar for Realm Realm
June 12, 2017

Realm Mobile Platform overview and demo

Realm Mobile Platform overview and demo
Realm World Tour Seoul: June 8th 2017

Avatar for Realm

Realm

June 12, 2017
Tweet

More Decks by Realm

Other Decks in Technology

Transcript

  1. ӝઓ ؘ੉ఠ ాन Native object JSON Backend object SQL Backend

    object JSON Native object SQLite/CoreData SQLite/CoreData e.g. REST, Parse, etc. Realm Mobile Database Realm Object Server Only Realm RMP vs. REST/JSON REST call Push Notification [email protected]
  2. Native object JSON Backend object SQL Backend object JSON Native

    object SQLite/CoreData SQLite/CoreData e.g. REST, Parse, etc. Realm Mobile Database Realm Object Server Only Realm REST call Push Notification Realm REST/JSON [email protected]
  3. Native object JSON Backend object SQL Backend object JSON Native

    object SQLite/CoreData SQLite/CoreData e.g. REST, Parse, etc. Realm Mobile Database Realm Object Server Only Realm Realm REST call Push Notification REST/JSON [email protected]
  4. ؊ ݆਷ ࢲߡ ӝמ • Realm Database SDK • ੋૐ

    • ঐഐചػ ੹࣠ • पदр زӝച • ୽ج ೧Ѿ • ࣻز ߔস • ࢲߡஏ ੉߮౟ ೩ٜ݂ • ݽפఠ݂ • ؘ੉ఠ ੽Ӕ • Ҋоਊࢿ • ۽٘ ߖ۠य • ࣻಣ झாੌ݂ • োࣘ ߔস [email protected] PE EE DE
  5. [email protected] زӝ Realm • ӝઓ Realmҗ زੌೞѱ ੘زೞݴ ߔӒۄ਍٘ زӝച

    ӝמ ನೣ • Configurationীࢲ Sync ࢸ੿ // ࢸ੿ ࣇস let syncServerURL = URL(string: "realm://localhost:9080/~/userRealm")! let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: syncServerURL)) // ਗѺ Realm ৌӝ let realm = try! Realm(configuration: config)
  6. [email protected] زӝ Realm ਬഋ ҕਊ Realm ѐੋ Realm • ݽٚ

    ࢎਊ੗о ࠅ ࣻ ੓਺ • ࢎਊ੗ח ੍ӝ ӂೠ݅ ࠗৈ • ౠ੿ ࢎਊ੗о ࣗਬ੗ • ׮ܲ ࢎਊ੗ী ӂೠ ࠗৈ ҕਬ Realm
  7. [email protected] ࣳೝށ दաܻয় ઁಿ ݾ۾ ࣳೝ ܻझ౟ ੢߄ҳפ ҕਊ Realm

    ѐੋ Realm • ݽٚ ࢎਊ੗о ࠅ ࣻ ੓਺ • ࢎਊ੗ח ੍ӝ ӂೠ݅ ࠗৈ • ౠ੿ ࢎਊ੗о ࣗਬ੗ • ׮ܲ ࢎਊ੗ী ӂೠ ࠗৈ ҕਬ Realm
  8. [email protected] ҕਊ Realm Realm য়࠳ં౟ ࢲߡ userA: ੍ӝ ӂೠ userB:

    ੍ӝ ӂೠ /productCatalog /productCatalog ؘ੉ఠ ಹद /productCatalog ؘ੉ఠ ಹद /productCatalog ؘ੉ఠ ಹद userC: ੍ӝ ӂೠ
  9. [email protected] ѐੋ Realm /userA/cart Realm য়࠳ં౟ ࢲߡ userA: য٘޹ ӂೠ

    userB: য٘޹ ӂೠ নߑೱ زӝച /userB/cart /userA/cart /userB/cart নߑೱ زӝച
  10. [email protected] ѐੋ-ҕਬ Realm /userA/shoppingList /userA/shoppingList Realm য়࠳ં౟ ࢲߡ নߑೱ زӝച

    /userA/shoppingList userA: য٘޹ ӂೠ userB: ੍ӝ/ॳӝ ӂೠ নߑೱ زӝച
  11. [email protected] Grant permission // ߸҃ೡ ਗѺ Realm URL let permissionChange

    = SyncPermissionChange(realmURL: realmURL, userID: anotherUserID, // ߸҃ೡ ࢎਊ੗ ID mayRead: true, // ੍ӝ ӂೠ ࠗৈ mayWrite: true, // ॳӝ ӂೠ ࠗৈ mayManage: false) // ҙܻ ӂೠ ޷ࠗৈ let managementRealm = try! user.managementRealm() try! managementRealm.write { managementRealm.add(permissionChange) } • mayRead: ੍ӝ ӂೠ • mayWrite: ॳӝ ӂೠ • mayManage: ҙܻ ӂೠ
  12. Function য়࠳ં౟ ࢲߡ੄ Ӗ۽ߥ ܻझ׬ API۽ ഐ୹غҊ changeEvent ё୓ܳ ੹׳ೞח

    Node.js ೣࣻ [email protected] Realm FunctionsBeta झ௼݀౟ ௑ࣛ ۽Ӓ ܻझ׬ೡ Realm प೯/੷੢/࢏ઁ
  13. [email protected] models (user web) let QuestionSchema = { name: 'Question',

    primaryKey: 'id', properties: { id: 'int', status: {type: 'bool', default: true}, date: 'date', question: 'string', author: {type: 'User'}, votes: {type: 'list', objectType: 'User'}, voteCount: 'int', isAnswered: {type: 'bool', default: false}, } } let UserSchema = { name: 'User', primaryKey: 'id', properties: { id: 'string' } } question-realmXX
  14. [email protected] Login and create user Realm.Sync.User.login(SERVER_URL, user, password, (error, user)

    => { if (!error) { let syncRealm = new Realm({ sync: { user: user, url: QUEST_SERVER_URL, }, schema: [UserSchema] }); syncRealm.write(() => { newAuthor = syncRealm.create('User', {id: sess.author}, true) }); } });
  15. [email protected] models (admin app) class Event: Object { dynamic var

    id = 0 dynamic var status = true dynamic var date = Date() dynamic var name = "" } class Question: Object { dynamic var id = 0 dynamic var status = true dynamic var date = Date() dynamic var question = "" dynamic var author: User? var votes = List<User>() dynamic var voteCount = 0 dynamic var isFavorite = false dynamic var isAnswered = false } class User: Object { dynamic var id = "" override static func primaryKey() -> String? { return "id" } } event-realm question-realmXX
  16. func application(_ application: UIApplication,
 didFinishLaunchingWithOptions launchOptions:
 [UIApplicationLaunchOptionsKey: Any]?) -> Bool

    { window = UIWindow(frame: UIScreen.main.bounds) if configureDefaultRealm() { window?.rootViewController = viewController } else { window?.rootViewController = UIViewController() logIn(animated: false) } return true } [email protected] Login func configureDefaultRealm() -> Bool { if let user = SyncUser.current { SyncManager.shared.errorHandler = { error, session in if let authError = error as? SyncAuthError, authError.code == .invalidCredential { authenticationFailureCallback?() } } return true } return false }
  17. [email protected] Create Event & Question Realm let syncServerURL = Constants.syncEventURL

    let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: SyncUser.current!, realmURL: syncServerURL)) let newEvent = Event(value: [eid, true, Date(), name]) try! realm.write { realm.add(newEvent) } // update event name let eventRealm = try! Realm(configuration: config) try! eventRealm.write { newEvent.name = name } // make question-xx Realm let baseURL = “\ (Constants.syncQuestionURL)\(String(eid))” let syncServerURL = URL(string: baseURL)! let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: SyncUser.current!, realmURL: syncServerURL)) let realm = try! Realm(configuration: config) let questions = realm.objects(Question.self)
  18. [email protected] Update question let sortProperties = [SortDescriptor (keyPath: “isAnswered”, ascending:

    true), SortDescriptor(keyPath: "isFavorite", ascending: false), SortDescriptor(keyPath: “voteCount", ascending: false)] questions = realm?.objects(Question.self) .filter("status = true”) .sorted(by: sortProperties) notificationToken = questions.addNotificationBlock { [weak self] (changes: RealmCollectionChange) in guard let tableView = self?.questTableView else { return } switch changes { case .initial: DispatchQueue.main.async { tableView.reloadData() } break // case .update } } case .update(_, let deletions, let insertions, let modifications): DispatchQueue.main.async { tableView.beginUpdates() tableView.insertRows(at: insertions.map({ IndexPath(row: $0, section: 0) }), with: .automatic) tableView.deleteRows(at: deletions.map({ IndexPath(row: $0, section: 0)}), with: .automatic) tableView.reloadRows(at: modifications.map({ IndexPath(row: $0, section: 0) }), with: .automatic) tableView.endUpdates() } break //
  19. [email protected] ੿ܻ • ؘ੉ఠח ۄ੉࠳۽ ٣झ௼ী ૒੽ ੽Ӕೡ ࣻ ੓ח

    ഋక੄ ё୓۽ ੷੢ • Realm ݽ؛ ௿ېझח 1 ؀ 1, ׮ ؀ ׮ ҙ҅ܳ ݂௼۽ ੷੢ • ؊ ബਯ੸ੋ ؘ੉ఠ ܻ࠙ ߂ Ӓܛചܳ ਤ೧ ٣झ௼ী рױೞѱ ৈ۞ Realmਸ ੘ࢿೞҊ ҙܻ • ׮নೠ ਬझா੉झী ݏѱ ࢲ۽ ׮ܲ realmਸ ࢎਊ೧ࢲ ਬোࢿ ૐ؀ • ୽ج ೧Ѿ ߂ झః݃ ݃੉Ӓۨ੉࣌ਸ ਤ೧ ೙ਃद ੗୓ ۽૒ਸ ೒۞Ӓੋ оמ