预计
@propertyWrapper
public struct Projected<T, Value> : AnyProjected where T : RLMObjectBase
@Projected
用于声明Projection
协议上应由 Realm 托管的属性。
使用示例:
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)
-
声明一个延迟初始化为类型默认值的属性。
声明
Swift
public init(_ projectedKeyPath: KeyPath<T, Value>)