A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mongodb.com/docs/realm-sdks/swift/latest/Classes/Projection.html below:

Projection Class Reference

Projection

Projection is a light weight model of the original Realm Object or EmbeddedObject. You can use Projection as a view model to minimize boilerplate.

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>
}

public class Address: EmbeddedObject {
    @Persisted var city: String = ""
    @Persisted var country = ""
}

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 friendsFirstName: ProjectedCollection<String>
}

### Supported property types

Projection can transform the original @Persisted properties in several ways:

Querying

You can retrieve all Projections of a given type from a Realm by calling the objects(_:) of Realm or init(projecting:) of Projection’s class:

let projections = realm.object(PersonProjection.self)
let personObject = realm.create(Person.self)
let singleProjection = PersonProjection(projecting: personObject)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4