Post

Replies

Boosts

Views

Activity

Reply to .transformable with ValueTransformer failing after Xcode 15.1 update
My understanding and usage of ValueTransformer was that the AnyClass returned from: override class func transformedValueClass() -> AnyClass was the expected type to be returned from: override func transformedValue(_ value: Any?) -> Any? This allowed for the value parameter passed to transformedValue to be Any? as defined by the function declaration. In Xcode 15.1 (iOS simulator 17.0.1) I was able to accept a SIMD3<Float> as the value parameter in my override of transformedValue and return a NSData. This matched my interpretation as detailed above. I was able to succesfully transform a SIMD3<Float> to NSData and implement reverseTransformedValue taking a NSData for its value parameter and returning a SIMD3<Float>. SwiftData would store and retrieve my SIMD3<Float> using my value transformer as expected. In Xcode 15.1 (iOS simulator 17.2) I get the error: Thread 1: "Unacceptable type of value for attribute: property = \"cameraPosition\"; desired type = NSData; given type = __SwiftValue; value = SIMD3<Float>(0.0, 0.0, 1.0)." This would imply override func transformedValue(_ value: Any?) -> Any? is now expecting / enforcing the value parameter should be the same type as the return from override class func transformedValueClass() -> AnyClass (in this case NSData) which is different to how the API worked in the iOS17.0.1 simulator. This cannot be right as it enforces only class types (AnyClass) can be transformed. Surely the idea is to be able to tranform any type (Any) to any type (Any) even if it is via a class (AnyClass) type. The ValueTransformer nomencleture and parameter types do not clearly specify the API's intended usage clearly. I have not been able to find any reference to this issue in release notes. I will assume this is a regression and will continue to use the iOS 17.0.1 simulator (as far as possible) in the meantime hoping a fix or revised ValueTransformer guidelines.
Dec ’23