M
M
MarsFM2018-09-03 15:04:48
Swift
MarsFM, 2018-09-03 15:04:48

How to convert from NSSet to another type?

Plz tell me how to convert the NSSet value to another type in Core Data?
There is a "Category" model which has the following fields:

@NSManaged public var name: String?
@NSManaged public var words: NSSet?

and "Word" model: One-to-many relationship, category can contain many words. And there is an extension in which there is a problem, here words is of type NSSet, I somehow need to convert it to Word. To make Errors:
@NSManaged public var name: String?
self.catergory.allWords.apend(word)
extension Category: CollectionCellViewModel {
    
    var fullName: String {
        set {
            name = newValue
        }
        get {
            return name ?? ""
        }
    }
    
    var allWords: [Word] {
        set {
            words = newValue // Cannot assign value of type '[Word]' to type 'NSSet?'
        }
        get {
            return words  // // Cannot convert return expression of type 'NSSet?' to return type '[Word]'
        }
    }
    
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
doublench21, 2018-09-03
@sportredwhite

5b8d4b617ba06911513554.png
I'm here for NSSet, if you're there NSSet?, then you know what to do.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question