executeFetchRequest doesn't return the NSManagedObject subclass

前端 未结 3 668
猫巷女王i
猫巷女王i 2021-02-14 11:20

This is for XCode 6 and Swift...

I\'m trying to make a fetch request to the managed object context but it\'s not returning the correct subclass.

I have already s

3条回答
  •  耶瑟儿~
    2021-02-14 11:26

    Just figured out the solution.

    I had to add the @objc attribute to allow the class to be compatible with Objective-C.

    Now the fetch request is returning a correct result of Tasks[]

    import Foundation
    import CoreData
    
    @objc(Task) // make compatible with objective-c
    class Task : NSManagedObject
    {
        @NSManaged var note: String!
        @NSManaged var completed: Bool
    }
    

    Reference: https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-XID_36

提交回复
热议问题