How to sort using Realm?

You can add an ascending parameter to the sorted method: data = data!.sorted(“date”, ascending: false) This sorts your WorkoutSet using the date field in descending order. Update With Swift 3 and the latest RealmSwift version this has now changed to: data = data!.sorted(byKeyPath: “date”, ascending: false) If you want to evaluate the sort criteria yourself … Read more

How to update an object in Realm Swift

Updating objects is just assign a value to a property within a write transaction. See our documentation. https://realm.io/docs/swift/latest/#updating-objects So you don’t need to delete and then add an object. Just assign new value to the property in write transaction like the following. let workouts = realm.objects(WorkoutsCount.self).filter(“date = %@”, removeTodaysItem) let realm = try! Realm() if … Read more

composite primary key realm/swift

For 1.0.1+ of Realm: class DbLocation: Object{ dynamic var id = 0 dynamic var tourId = 0 dynamic var compoundKey = “” override static func primaryKey() -> String? { return “compoundKey” } func setup(id: Int, tourId: Int){ self.id = id self.tourId = tourId self.compoundKey = compoundKeyValue() } func compoundKeyValue() -> String { return “\(id)\(tourId)” } … Read more

Kotlin data class of RealmObject

Realm doesn’t support Data classes currently. You can see an example of how to write Realm compatible model classes in Kotlin here: https://github.com/realm/realm-java/tree/master/examples/kotlinExample/src/main/kotlin/io/realm/examples/kotlin/model public open class Person( @PrimaryKey public open var name: String = “”, public open var age: Int = 0, public open var dog: Dog? = null, public open var cats: RealmList<Cat> = … Read more

Xcode unable to find strip-frameworks.sh directory

From the error message, it seems like, you didn’t added Realm.framework and RealmSwift.framework to the Embedded Binaries pane, which you find in the General tab of your project, as shown below: For further validation, you can check the tab Build Phases. It should look like below: Note: Make sure that the run script phase comes … Read more

Realm accessed from incorrect thread – again

Instances of Realm and Object are thread-contained. They cannot be passed between threads or that exception will occur. Since you’re passing the completion block itself to the background queue at the same time the queue is being created (As Dave Weston said), any Realm objects inside that block will most certainly not have been created … Read more

tech