This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let coffeDrinks = repository.queryAll(returningClass: CoffeeDrink.self) | |
let cofferRate = coffeDrinks!.filter { $0.rating == 4 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let data = "{\"name\": \"Tennis ball\"}".data(using: .utf8)! | |
repository.save(saveClass: DogToy.self, jsonData: data, update: false) { result in | |
switch result { | |
case .success: | |
break | |
case .failure: | |
break | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let aDog = Dog(value: ["name": "Lulu", "age": 3]) | |
let anotherDog = Dog(value: ["name": "Nana", "age": 2]) | |
// Instead of using pre-existing dogs... | |
let aPerson = Person(value: [123, "Jane", [aDog, anotherDog]]) | |
// ...we can create them inline | |
let anotherPerson = Person(value: [456, "Jane", [["Buster", 5], ["Buddy", 6]]]) | |
repository.save(entities: [aPerson, anotherPerson], update: true) { result in | |
switch result { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let repository = PetRepository() | |
repository.save(entity: dog, update: false) { result in | |
switch result { | |
case .success: | |
// Handle success here | |
print("Handle success here") | |
case .failure: | |
print("Handle failed here") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RealmSwift | |
class Person: Object { | |
@Persisted(primaryKey: true) var id = 0 | |
@Persisted var name = "" | |
// To-many relationship - a person can have many dogs | |
@Persisted var dogs: List<Dog> | |
// Inverse relationship - a person can be a member of many clubs | |
@Persisted(originProperty: "members") var clubs: LinkingObjects<DogClub> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RealmSwift | |
import QRealmManager | |
class PetRepository: DatabaseConfigurable { | |
var realmMemoryType: RealmMemoryType { | |
return .inStorage | |
} | |
var schemaName: String? { | |
return "PetSchema" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thêm bằng dòng sau: | |
https://github.com/lexuanquynh/QRealmManagerPackage.git | |
Sau đó import: | |
import QRealmManagerPackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pod 'QRealmManager' | |
sau đó import thư viện: | |
import QRealmManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var migrationBlock: MigrationBlock? { | |
let migrationBlock: MigrationBlock = { migration, oldSchemaVersion in | |
if oldSchemaVersion < 1 { | |
// Rename the "name" property to "yourName". | |
// The renaming operation should be done outside of calls to `enumerateObjects(ofType: _:)`. | |
migration.renameProperty(onType: MigrationSample.className(), from: "age", to: "yearsSinceBirth") | |
// migration.renameProperty(onType: MigrationSample.className(), from: "name", to: "yourName") | |
} | |
// The enumerateObjects(ofType:_:) method iterates over |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var objectTypes: [Object.Type]? { | |
return [DogToy.self, Dog.self, DogClub.self, Person.self] | |
} |