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

Realm Japan meetup #13

Realm Japan meetup #13

- Release Realm React Native!
- Background query (Collection notifications)
- How to use subquery

Kishikawa Katsumi

July 24, 2016
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. const Realm = require('realm'); class AwesomeProject extends Component { render()

    { class Person {} Dog.schema = { name: 'Dog', primaryKey: 'name', properties: { name: 'string', age: {type: 'int', default: 0}, }, }; const realm = new Realm({schema: [Dog]}); realm.write(() => { realm.create('Dog', { name: 'Hal Incandenza', age: 17 }); }); return ( <View style={styles.container}> <Text style={styles.welcome}> Count of Dogs in Realm: {realm.objects('Dog').length} </Text> </View> ); } }
  2. const Realm = require('realm'); class AwesomeProject extends Component { render()

    { class Person {} Dog.schema = { name: 'Dog', primaryKey: 'name', properties: { name: 'string', age: {type: 'int', default: 0}, }, }; const realm = new Realm({schema: [Dog]}); realm.write(() => { realm.create('Dog', { name: 'Hal Incandenza', age: 17 }); }); return ( <View style={styles.container}> <Text style={styles.welcome}> Count of Dogs in Realm: {realm.objects('Dog').length} </Text> </View> ); } }
  3. const Realm = require('realm'); class AwesomeProject extends Component { render()

    { class Person {} Dog.schema = { name: 'Dog', primaryKey: 'name', properties: { name: 'string', age: {type: 'int', default: 0}, }, }; const realm = new Realm({schema: [Dog]}); realm.write(() => { realm.create('Dog', { name: 'Hal Incandenza', age: 17 }); }); return ( <View style={styles.container}> <Text style={styles.welcome}> Count of Dogs in Realm: {realm.objects('Dog').length} </Text> </View> ); } }
  4. const Realm = require('realm'); class AwesomeProject extends Component { render()

    { class Person {} Dog.schema = { name: 'Dog', primaryKey: 'name', properties: { name: 'string', age: {type: 'int', default: 0}, }, }; const realm = new Realm({schema: [Dog]}); realm.write(() => { realm.create('Dog', { name: 'Hal Incandenza', age: 17 }); }); return ( <View style={styles.container}> <Text style={styles.welcome}> Count of Dogs in Realm: {realm.objects('Dog').length} </Text> </View> ); } }
  5. const Realm = require('realm'); class AwesomeProject extends Component { render()

    { class Person {} Dog.schema = { name: 'Dog', primaryKey: 'name', properties: { name: 'string', age: {type: 'int', default: 0}, }, }; const realm = new Realm({schema: [Dog]}); realm.write(() => { realm.create('Dog', { name: 'Hal Incandenza', age: 17 }); }); return ( <View style={styles.container}> <Text style={styles.welcome}> Count of Dogs in Realm: {realm.objects('Dog').length} </Text> </View> ); } }
  6. const Realm = require('realm'); class AwesomeProject extends Component { render()

    { class Person {} Dog.schema = { name: 'Dog', primaryKey: 'name', properties: { name: 'string', age: {type: 'int', default: 0}, }, }; const realm = new Realm({schema: [Dog]}); realm.write(() => { realm.create('Dog', { name: 'Hal Incandenza', age: 17 }); }); return ( <View style={styles.container}> <Text style={styles.welcome}> Count of Dogs in Realm: {realm.objects('Dog').length} </Text> </View> ); } }
  7. 3FTVMUT5ח㼎ׅ׷鸐濼 timeline = realm.objects(Tweet) .sorted("createdAt", ascending: false) notificationToken = timeline?.addNotificationBlock

    { (results, error) -> () in if let _ = error { return } count = results.count self.tableView.reloadData() } return count
  8. timeline = realm.objects(User) notificationToken = timeline?.addNotificationBlock { (results, error) ->

    () in if let _ = error { return } self.tableView.reloadData() } 3FTVMUT5ח㼎ׅ׷鸐濼
  9. class Project: Object { dynamic var id = "" dynamic

    var name = "" let todos = List<Todo>() override class func primaryKey() -> String? { return "id" } } class Todo: Object { dynamic var name = "" dynamic var completionDate: NSDate? dynamic var user: User? } class User: Object { dynamic var name = "" }
  10. class Project: Object { dynamic var id = "" dynamic

    var name = "" let todos = List<Todo>() override class func primaryKey() -> String? { return "id" } } class Todo: Object { dynamic var name = "" dynamic var completionDate: NSDate? dynamic var user: User? } class User: Object { dynamic var name = "" }
  11. class Project: Object { dynamic var id = "" dynamic

    var name = "" let todos = List<Todo>() override class func primaryKey() -> String? { return "id" } } class Todo: Object { dynamic var name = "" dynamic var completionDate: NSDate? dynamic var user: User? } class User: Object { dynamic var name = "" }
  12. 1SPKFDU" 1SPKFDU# 1SPKFDU$ 1SPKFDU% 5PEP ,BUTVNJ  5PEP ,BUTVNJ 5PEP

    .BLPUP 5PEP ,BUTVNJ 5PEP .BLPUP  5PEP ,BUTVNJ  5PEP ,BUTVNJ  5PEP .BLPUP  5PEP .BLPUP  5PEP .BLPUP 5PEP .BLPUP
  13. 1SPKFDU" 1SPKFDU# 1SPKFDU$ 1SPKFDU% 5PEP ,BUTVNJ  5PEP ,BUTVNJ 5PEP

    .BLPUP 5PEP ,BUTVNJ 5PEP .BLPUP  5PEP ,BUTVNJ  5PEP ,BUTVNJ  5PEP .BLPUP  5PEP .BLPUP  5PEP .BLPUP 5PEP .BLPUP
  14. let projects = realm .objects(Project) .filter("ANY todos.completionDate == nil AND

    ANY todos.user.name == %@", "Katsumi") print(projects)
  15. 1SPKFDU" 1SPKFDU# 1SPKFDU$ 1SPKFDU% 5PEP ,BUTVNJ  5PEP ,BUTVNJ 5PEP

    .BLPUP 5PEP ,BUTVNJ 5PEP .BLPUP  5PEP ,BUTVNJ  5PEP ,BUTVNJ  5PEP .BLPUP  5PEP .BLPUP  5PEP .BLPUP 5PEP .BLPUP
  16. let todos = realm .objects(Todo) .filter("completionDate == nil AND user.name

    == %@", "Katsumi") let projects = realm.objects(Project).filter("ANY todos IN %@", todos) print(projects)