如何使用自动生成的Core Data AddTo ...功能

时间:2017-03-13 17:19:20

标签: core-data swift3 func nsset xcode8.2

当我从顶部菜单的编辑器中选择“Create NSManagedObject Subclass”时,我的代码会自动生成。

我想尝试使用两种功能,但我似乎无法访问它们。第一个是addToListsRel,另一个是removeFromListsRel

使用点符号,它们似乎不可用,那么我怎么能用它们?

import Foundation
import CoreData


extension Ent_Catalog {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<Ent_Catalog> {
        return NSFetchRequest<Ent_Catalog>(entityName: "Ent_Catalog");
    }

    @NSManaged public var brand: String?
    @NSManaged public var id: Int32
    @NSManaged public var image: NSData?
    @NSManaged public var name: String?
    @NSManaged public var price: NSDecimalNumber?
    @NSManaged public var qty: NSDecimalNumber?
    @NSManaged public var size: String?
    @NSManaged public var itemsRel: Ent_Items?
    @NSManaged public var listsRel: NSSet?
    @NSManaged public var ingredientsRel: NSSet?
    @NSManaged public var sectionsRel: Ent_Sections?

}

// MARK: Generated accessors for listsRel
extension Ent_Catalog {

    @objc(addListsRelObject:)
    @NSManaged public func addToListsRel(_ value: Ent_Lists)

    @objc(removeListsRelObject:)
    @NSManaged public func removeFromListsRel(_ value: Ent_Lists)

    @objc(addListsRel:)
    @NSManaged public func addToListsRel(_ values: NSSet)

    @objc(removeListsRel:)
    @NSManaged public func removeFromListsRel(_ values: NSSet)

}

// MARK: Generated accessors for ingredientsRel
extension Ent_Catalog {

    @objc(addIngredientsRelObject:)
    @NSManaged public func addToIngredientsRel(_ value: Ent_Ingredients)

    @objc(removeIngredientsRelObject:)
    @NSManaged public func removeFromIngredientsRel(_ value: Ent_Ingredients)

    @objc(addIngredientsRel:)
    @NSManaged public func addToIngredientsRel(_ values: NSSet)

    @objc(removeIngredientsRel:)
    @NSManaged public func removeFromIngredientsRel(_ values: NSSet)

}

1 个答案:

答案 0 :(得分:0)

我认为点符号看起来像Catalog.listsRel.addToListsRel。事实证明它实际上是Catalog.addToListsRel

希望这有助于其他人。