Implement NSValueTransformer for converted attributes in Swift

I am trying to implement NSValue Transformer, which should help me save a double array to the underlying data using the Transformable attribute.

So, I tried to implement transformValueClass. But NSArray.class () is crossed out. Unfortunately, I did not find a reason for this. My method is as follows

class PacePerK:NSValueTransformer{
     class func transformedValueClass() -> AnyClass!
        {
           return NSArray.class()
        }
}

I get the following compiler errors: The expected name of the member following '.' Expected identifier in class declaration

Unfortunately, they really do not help me.

Why is NSArray.class crossed out? How can I return the NSArray class without causing a compiler error?

+4
source share
1 answer

, Swift :

NSArray.self

, ValueClass "". :

class PacePerK:NSValueTransformer{
    override class func transformedValueClass() -> AnyClass!
    {
        return NSArray.self
    }
}
+4

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


All Articles