NSValueTransformer for C structs in Core Data
-
20-06-2021 - |
Question
How do I create a NSValueTransformer
for a C struct, such as a CGRect
in Core Data?
Apparently transformedValue
& reverseTransformedValue
require and id
. Is there a way to pass a void*
, or a better way to do this?
Solution
Use NSValue to wrap C pointers.
[NSValue valueWithPointer:&struct]
Specifically for CGRect, you can use
[NSValue valueWithCGRect:rect]
which is declared in UIKit/UIGeometry.h
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow