Hey Lee.
I’m probably saying it wrong if you think it shouldn’t involve a Realm.
I’m talking about setting properties for a Realm object and then adding it in the prescribed way.
Your example is about adding a Group Realm object by appending Group() with the @ObservedResults property wrapper and the using .append()
Your example is extremely basic. For anything more complex, there is no example and that was my comment – either the example is incomplete or there isn’t a good way to do this.
In my app I am checking to see if there is a plan with a location like this:
@ObservedResults(Plan.self) var plans
@StateRealmObject var location: Location
...
if let plan = plans.filter("location._id = %@", location._id).first {
// show plan
} else {
// add location to plan like this:
$plans.append(Plan(_id: UUID(), _partition: "user=\(app.currentUser!.id)",location: self.location))
// because if I do it as prescribed like this:
$plans.append(Plan())
// it works, but there is no way to add the location, so there's just an empty Plan object added to the database
}
This doesn’t work.
I’ve tried to pass in the location
as a var
, as @ObservedRealmObject
, and as @StateRealmObject
as shown above. No matter what it always shows the error:
Object is already managed by another Realm. Use create…
I’m not super interested in opening a GitHub issue. I’m more interested in documentation and/or examples that goes beyond the most basic usage. Again, surely there is a way to do this, but either I’m misunderstanding how to do this in Realm, or I’m not saying it correctly. Either are entirely possible.