Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
x.y.z Release notes (yyyy-MM-dd)
=============================================================
### Enhancements
* None.
* Add support for KeyPath initializiation for LinkingObjects declared with @Persisted:
`@Persisted(originProperty: \.dogs) var persons: LinkingObjects<Person>

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-swift/issues/????), since v?.?.?)
Expand Down
3 changes: 3 additions & 0 deletions RealmSwift/PersistedProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ extension Persisted where Value: LinkingObjectsProtocol {
public init(originProperty: String) {
self.init(wrappedValue: Value(fromType: Value.Element.self, property: originProperty))
}
public init<V>(originProperty: KeyPath<Value.Element, V?>) where Value.Element: ObjectBase, V: ObjectBase {
self.init(wrappedValue: Value(fromType: Value.Element.self, property: _name(for: originProperty)))
}
}
extension LinkingObjects: LinkingObjectsProtocol {}

Expand Down
2 changes: 1 addition & 1 deletion RealmSwift/Tests/ModernTestObjects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ModernAllTypesObject: Object {
@Persisted var mapOptObjectId: Map<String, ObjectId?>
@Persisted var mapOptUuid: Map<String, UUID?>

@Persisted(originProperty: "objectCol")
@Persisted(originProperty: \.objectCol)
var linkingObjects: LinkingObjects<ModernAllTypesObject>
}

Expand Down