在CoreStore中使用Field.Relationship要符合FieldRelationshipType协议需要哪些步骤?

问题描述 投票:0回答:1

尝试使用 Swift 5.10 学习 CoreStore 9.2.0

出现编译错误后,我尝试使用别名以及有时需要符合

@Field.Relationship
的方法来支持我的
FieldRelationshipType
属性。 一致性没有起作用,并且在我的逆声明中推断通用参数也存在错误。

这是我的简单基本情况:

import Foundation
import CoreStore

class MICSelecta: CoreStoreObject {
    @Field.Relationship("performances", inverse: \MICPerformance.$selecta)
    var performances: Set<MICPerformance>
}

extension MICSelecta: FieldRelationshipToManyType {
    typealias ObjectType = MICSelecta
    typealias DestinationObjectType = MICPerformance
}

class MICPerformance: CoreStoreObject {
    @Field.Relationship("selecta")
    var selecta: MICSelecta
}

extension MICPerformance: FieldRelationshipToOneType {
    typealias ObjectType = MICPerformance
    typealias DestinationObjectType = MICSelecta
}

我在 GitHub 上搜索了示例,但没有看到任何诸如此类的显式扩展,这是有道理的,因为该库可能能够反映这些配置以及其他一些配置。

我还尝试使用 4-5 个别名和 5 个方法进行更彻底的声明,这些方法可以将实体转换为各种格式,例如

NSManagedObject

错误: 与反向声明一致:

Generic parameter 'D' could not be inferred

Field.Relationship
中的
MICPerformance
行有两个错误:

Generic struct 'Relationship' requires that 'MICSelecta' conform to 'FieldRelationshipType'

Referencing initializer 'init(_:deleteRule:versionHashModifier:previousVersionKeyPath:affectedByKeyPaths:)' on 'FieldContainer.Relationship' requires that 'MICSelecta' conform to 'FieldRelationshipToOneType'

swift core-data protocols corestore
1个回答
0
投票

我将

var selecta: MICSelecta?
设为可选并编译了

© www.soinside.com 2019 - 2024. All rights reserved.