简体   繁体   中英

Swift - CoreData’s NSManagedObject subclass

When creating NSManagedObject subclasses in Swift, I get an error:

2015-02-12 00:12:57.662 MyApp[1934:272844] CoreData: warning: Unable to load class named ‘ClassName' for entity 'ClassName'.  Class not found, using default NSManagedObject instead.

I can fix this by manually adding @objc(ClassName) in the Swift subclass, but not only does this defeat the purpose of automatic subclassing, but I don't want to waste my development time adding this to all two dozen NSManagedObject subclasses.

Originally I did this and just got over it. But this time I needed to change my model and generate all subclasses again and have a deadline coming up, so what would be the correct way to overcome this error so regenerating my model's subclasses doesn't mean wasting so much time/patience.

Thanks as ever

You are out of luck. Some things in Swift just do not (yet) work the way they used to in Objective-C.

Consider writing a script (in Perl, Python - or Swift!) to insert the missing line. For example, the first line of the class declaration is always on the same line, so it should be trivial to extract the class name and insert the corresponding @objC call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM