@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? = nil
    @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(\ 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.