does anyone have a working example of a fetched-property in core-data?

后端 未结 3 835
广开言路
广开言路 2021-01-31 18:08

I have tried to use fetched properties a couple of times, and although it seems to be the right approach, it never works.

In my latest attempt I added the fetch

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 18:38

    Adding to @Peter's answer. Here's how I got it working in Swift 2.0 and Xcode 7:

    import Foundation
    import CoreData
    
    @objc(Card)
    class Card: NSManagedObject {
    
        @NSManaged var statsOfTypeOne: [Stat]
    
    }
    

    And then, to read the fetched property:

    managedObjectContext.refreshObject(someCard, mergeChanges: true)
    // This works and returns [Stat] type
    someCard.statsOfTypeOne
    // So does this
    someCard.valueForkey("statsOfTypeOne") as! [Stat]
    

提交回复
热议问题