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

Realm Japan meetup #16

Realm Japan meetup #16

- Realm Objective-C/Swift 1.0.1
- Realm video tutorial
- What's new in CoreData

Kishikawa Katsumi

July 24, 2016
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. Recent Updates • Realm Objective-C/Swift 1.0.1 (was 1.0.0) • Realm

    Java 1.0.1 (was 1.0.0) • Realm React Native 0.13.0 • Realm Xamarin 0.76.0 [email protected] [email protected]
  2. What’s new in Core Data • Simple Core Data Stack

    • NSPersistentStoreDescription (Like RealmConfiguratin?) • Type safety • Subclass generation • Version Pinning [email protected] [email protected]
  3. Simpler Core Data Stack [email protected] lazy var managedObjectModel: NSManagedObjectModel =

    { let modelURL = NSBundle.mainBundle().URLForResource("Example", withExtension: "momd")! return NSManagedObjectModel(contentsOfURL: modelURL)! }() lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = { var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel) let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("Example.sqlite") var error: NSError? = nil var failureReason = "There was an error creating or loading the application's saved data." if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil { coordinator = nil NSLog("Unresolved error \(error), \(error!.userInfo)") abort() } return coordinator }() lazy var managedObjectContext: NSManagedObjectContext? = { let coordinator = self.persistentStoreCoordinator if coordinator == nil { return nil } var managedObjectContext = NSManagedObjectContext() managedObjectContext.persistentStoreCoordinator = coordinator return managedObjectContext }()
  4. Simpler Core Data Stack [email protected] lazy var persistentContainer: NSPersistentContainer =

    { let container = NSPersistentContainer(name: "Example") container .loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error { fatalError("Unresolved error \(error), \(error.userInfo)") } }) return container }()
  5. Typed fetch request [email protected] let request: NSFetchRequest<Dog> = Dog.fetchRequest() request.predicate

    = Predicate(format: "...") request.fetchBatchSize = 20 let dogs = try! persistentContainer.viewContext.fetch(request) print(dogs)
  6. Typed fetch request [email protected] let request: NSFetchRequest<Dog> = Dog.fetchRequest() request.predicate

    = Predicate(format: "...") request.fetchBatchSize = 20 let dogs = try! persistentContainer.viewContext.fetch(request) print(dogs)
  7. Auto generation subclasses [email protected] import Foundation import CoreData class Dog:

    NSManagedObject { } extension Dog { @nonobjc class func fetchRequest() -> NSFetchRequest<Dog> { return NSFetchRequest<Dog>(entityName: "Dog"); } @NSManaged var age: Int64 @NSManaged var name: String? }
  8. Where to find us • ! Realm Japan User Group:

    facebook.com/groups/realmjp • ! Twitter: twitter.com/realmJapan • GitHub: github.com/realm • ! StackOverflow: ja.stackoverflow.com/questions/tagged/realm • ! Email: [email protected] • ! Slack: slack.realm.io/ [email protected] [email protected]