9

I'm trying to understand which is the good way (and suggested by Apple) for storing an array of String ([String]) using the framework Core Data with SwiftUI.

I haven't found any clear documentation about.

For what I saw, I should create an attribute of type Transformable and then set the "Custom Class" to [String]

enter image description here

enter image description here

But then I start to see some warnings at build time:

warning: Misconfigured Property: Wine.pairings is using a nil or insecure value transformer. Please switch to NSSecureUnarchiveFromDataTransformerName or a custom NSValueTransformer subclass of NSSecureUnarchiveFromDataTransformer

So, I'm wondering that maybe this is not the good approach.

2
  • My recommendation is to forget heavy NSCoding and en-/decode the string to/from JSON with Codable and map it with a computed property. Commented May 6, 2021 at 18:24
  • Yes, I was thinking about a way like this, but I would like to use the native API offered by Core Data Commented May 7, 2021 at 7:36

1 Answer 1

11

screenshot of core data model

If you put NSSecureUnarchiveFromData into the Transformer field (the one above custom class in your data model) the warning goes away

Sign up to request clarification or add additional context in comments.

1 Comment

ah perfect, I see that it works, in fact it has generated in the properties file the following attribute public var pairings: [String]? { get set }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.