Projected

@propertyWrapper
public struct Projected<T, Value> : AnyProjected where T : RLMObjectBase

@Projected is used to declare properties on Projection protocols which should be managed by Realm.

Example of usage:

public class Person: Object {
    @Persisted var firstName = ""
    @Persisted var lastName = ""
    @Persisted var address: Address?
    @Persisted var friends: List<Person>
    @Persisted var reviews: List<String>
}

class PersonProjection: Projection<Person> {
    @Projected(\Person.firstName) var firstName
    @Projected(\Person.lastName.localizedUppercase) var lastNameCaps
    @Projected(\Person.address.city) var homeCity
    @Projected(\Person.friends.projectTo.firstName) var firstFriendsName: ProjectedCollection<String>
}

let people: Results<PersonProjection> = realm.objects(PersonProjection.self)
  • Declares a property which is lazily initialized to the type’s default value.

    Declaration

    Swift

    public init(_ projectedKeyPath: KeyPath<T, Value>)