Share
Embed
Realm Mobile Platform overview and demo
Realm Mobile Platform overview and demo
Realm World Tour Seoul: June 8th 2017
Realm
June 12, 2017
Transcript
50 slides
-
Realm Mobile Database Objects Queries Notifications Transactions UI events, Network,
more Modify Make Up Trigger [email protected] -
ӝઓ ؘఠ ాन 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] -
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] -
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] -
؊ ݆ ࢲߡ ӝמ • Realm Database SDK • ੋૐ
• ঐഐചػ ࣠ • पदр زӝച • ج ೧Ѿ • ࣻز ߔস • ࢲߡஏ ߮ ೩ٜ݂ • ݽפఠ݂ • ؘఠ Ӕ • Ҋоਊࢿ • ۽٘ ߖ۠य • ࣻಣ झாੌ݂ • োࣘ ߔস [email protected] PE EE DE -
[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) -
[email protected] زӝ Realm ਬഋ ҕਊ Realm ѐੋ Realm • ݽٚ
ࢎਊо ࠅ ࣻ • ࢎਊח ੍ӝ ӂೠ݅ ࠗৈ • ౠ ࢎਊо ࣗਬ • ܲ ࢎਊী ӂೠ ࠗৈ ҕਬ Realm -
[email protected] ࣳೝށ दաܻয় ઁಿ ݾ۾ ࣳೝ ܻझ ߄ҳפ ҕਊ Realm
ѐੋ Realm • ݽٚ ࢎਊо ࠅ ࣻ • ࢎਊח ੍ӝ ӂೠ݅ ࠗৈ • ౠ ࢎਊо ࣗਬ • ܲ ࢎਊী ӂೠ ࠗৈ ҕਬ Realm -
[email protected] ҕਊ Realm Realm য়࠳ં ࢲߡ userA: ੍ӝ ӂೠ userB:
੍ӝ ӂೠ /productCatalog /productCatalog ؘఠ ಹद /productCatalog ؘఠ ಹद /productCatalog ؘఠ ಹद userC: ੍ӝ ӂೠ -
[email protected] ѐੋ Realm /userA/cart Realm য়࠳ં ࢲߡ userA: য٘ ӂೠ
userB: য٘ ӂೠ নߑೱ زӝച /userB/cart /userA/cart /userB/cart নߑೱ زӝച -
[email protected] ѐੋ-ҕਬ Realm /userA/shoppingList /userA/shoppingList Realm য়࠳ં ࢲߡ নߑೱ زӝച
/userA/shoppingList userA: য٘ ӂೠ userB: ੍ӝ/ॳӝ ӂೠ নߑೱ زӝച -
[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: ҙܻ ӂೠ -
Function য়࠳ં ࢲߡ Ӗ۽ߥ ܻझ API۽ ഐغҊ changeEvent ёܳ ׳ೞח
Node.js ೣࣻ [email protected] Realm FunctionsBeta झ݀ ࣛ ۽Ӓ ܻझೡ Realm प೯//ઁ -
[email protected] Overview Server-side Realms Device-side Realms Realm Object Server Real-time
Sync event-realm question-realmXX Users (Web) Managers (app) -
[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 -
[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) }); } }); -
[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 -
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 } -
[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) -
[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 // -
[email protected] ܻ • ؘఠח ۄ࠳۽ ٣झী Ӕೡ ࣻ ח
ഋక ё۽ • Realm ݽ؛ ېझח 1 1, ҙ҅ܳ ݂۽ • ؊ ബਯੋ ؘఠ ܻ࠙ ߂ Ӓܛചܳ ਤ೧ ٣झী рױೞѱ ৈ۞ Realmਸ ࢿೞҊ ҙܻ • নೠ ਬझாझী ݏѱ ࢲ۽ ܲ realmਸ ࢎਊ೧ࢲ ਬোࢿ ૐ • ج ೧Ѿ ߂ झః݃ ݃Ӓۨ࣌ਸ ਤ೧ ਃद ۽ਸ ۞Ӓੋ оמ