Basic data: No NSValueTransformer with class name XXX was found for attribute YYYY on object ZZZZ

I have a CoreData model installed in the xcdatamodel file.

My YYYY attribute has a transformable type, and I set the name tranformer in the data model inspector.

In my case, I saved [CLLocation]in my model.

class LocationArrayTransformer : NSValueTransformer {


    override func transformedValue(value: AnyObject?) -> AnyObject? {

        let locations = value as! [CLLocation]

        return NSKeyedArchiver.archivedDataWithRootObject(locations)
    }

    override func reverseTransformedValue(value: AnyObject?) -> AnyObject? {

        let data = value as! NSData

        return NSKeyedUnarchiver.unarchiveObjectWithData(data)
    }


}

This is my value transformer.

But for some reason, I still get a warning in the console: No NSValueTransformer with class name XXX was found for attribute YYYY on entity ZZZZ

Any idea why?

+4
source share
1 answer

I spent a lot of time on this so as not to share the solution I found:

I needed to make a subclass NSValueTransformeravailable to Objc.

@objc(LocationArrayTransformer)
class LocationArrayTransformer : NSValueTransformer {
 ....
}

Simply.


@Sbooth, Swift . @objc . MyApp.Mytransformer !

+18

Source: https://habr.com/ru/post/1607564/


All Articles