It was written 5 years ago so it's possible that things were more confused back then 😃
Worked through cleaning up the code.
Thanks for the response.
Yes, NSStrings are converted back to String so internal to the ValueTransformer you can simply pass a String value back where the ValueTransformer is defined to return NSString.self.
So there is no need to wrap a conversion from String to NSString.
override class func transformedValueClass() - AnyClass
{
return NSString.self
}
override func transformedValue(_ value: Any?) - Any?
{
let str = convert(value) // returns a String
return str
}
This needs to be within the Objective-C side since the string is being handed back to a Cocoa Binding. So have to return NSObjects. So using NSNumbers for bool conversion works too.
What was also less obvious what that there was a work around that generated a string for the Entity directly, bypassing the ValueTransformer. So buried in the IB Bindings inspector you could see that but not obvious just from reading the code. Alas, the importance of documenting code work arounds and explaining which code isn't actually working.
Topic:
Programming Languages
SubTopic:
Swift
Tags: