Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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: 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This'll allow specifying any type of property as the origin property and ideally it'd be constrained to links.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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