gpt4 book ai didi

swift - 如何在 Realm 中列出 LinkingObjects 属性?

转载 作者:行者123 更新时间:2023-11-28 06:29:55 34 4
gpt4 key购买 nike

我需要列出一个对象的所有 LinkingObjects 类型的属性。

class Dogs: Object {
dynamic var name: String = ""
dynamic var age: Int = 0
dynamic var owner: Persons?
}


class Cats: Object {
dynamic var name: String = ""
dynamic var age: Int = 0
dynamic var owner: Persons?
}


class Persons: Object {
dynamic var name: String = ""
dynamic var address: String = ""

let dogs = LinkingObjects(fromType: Dogs.self, property: "owner")
let cats = LinkingObjects(fromType: Cats.self, property: "owner")
}

ObjectSchema 正确返回架构:

let person = Persons()
let schema = person.objectSchema
print(schema)

结果:

Persons {
name {
type = string;
objectClassName = (null);
linkOriginPropertyName = (null);
indexed = NO;
isPrimary = NO;
optional = NO;
}
address {
type = string;
objectClassName = (null);
linkOriginPropertyName = (null);
indexed = NO;
isPrimary = NO;
optional = NO;
}
dogs {
type = linking objects;
objectClassName = Dogs;
linkOriginPropertyName = owner;
indexed = NO;
isPrimary = NO;
optional = NO;
}
cats {
type = linking objects;
objectClassName = Cats;
linkOriginPropertyName = owner;
indexed = NO;
isPrimary = NO;
optional = NO;
}
}

但是,objectSchema.properties 不返回 LinkingObjects 属性。

let properties = schema.properties
print(properties)

返回:

[name {
type = string;
objectClassName = (null);
linkOriginPropertyName = (null);
indexed = NO;
isPrimary = NO;
optional = NO;
}, address {
type = string;
objectClassName = (null);
linkOriginPropertyName = (null);
indexed = NO;
isPrimary = NO;
optional = NO;
}]

狗和猫的属性在哪里?

谢谢。

最佳答案

我找到了解决方案:

let computedProperties = Persons.sharedSchema()?.computedProperties

关于swift - 如何在 Realm 中列出 LinkingObjects 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40635270/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com