Storing an array or dict with CoreStoreObject? #180

Closed
opened 2025-12-29 15:26:18 +01:00 by adam · 4 comments
Owner

Originally created by @kevinrenskers on GitHub (Oct 24, 2017).

Is it possible to store an array or dict with CoreStoreObject? I noticed in another ticket that someone answered that question with one word: Transformable.

But something like this does not compile:

class Receipt: CoreStoreObject {
  let images = Transformable.Optional<[String]>("images")
}

screen shot 2017-10-24 at 17 13 29

Same goes for storing a [String: Any] dict, where I know all properties can be stored safely into Core Data (works great before refactoring to use CoreStoreObject). Any help would be greatly appreciated, thanks :)

Originally created by @kevinrenskers on GitHub (Oct 24, 2017). Is it possible to store an array or dict with CoreStoreObject? I noticed in another ticket that someone answered that question with one word: `Transformable`. But something like this does not compile: ``` class Receipt: CoreStoreObject { let images = Transformable.Optional<[String]>("images") } ``` ![screen shot 2017-10-24 at 17 13 29](https://user-images.githubusercontent.com/229384/31965006-3c744656-b906-11e7-8ab3-6b1e90862b80.png) Same goes for storing a `[String: Any]` dict, where I know all properties can be stored safely into Core Data (works great before refactoring to use CoreStoreObject). Any help would be greatly appreciated, thanks :)
adam added the enhancementfixed labels 2025-12-29 15:26:18 +01:00
adam closed this issue 2025-12-29 15:26:18 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Oct 25, 2017):

Transformer currently only supports NSCoding. I've been planning to support Swift Codable types as well but haven't gotten around it yet, sorry. I wanted to provide a way to specify the encoder type (e.g. JSONEncoder or PropertyListEncoder), but some parts of Transformable may need rethinking because encoders don't have a common protocol, so we need to pass in an instance.

I'll bump this in my priority, in the meantime you can use NSArray and NSDictionary, which is what CoreData originally supports (through objc bridging). It might not have binary compatibility with the future Codable though.

@JohnEstropia commented on GitHub (Oct 25, 2017): `Transformer` currently only supports `NSCoding`. I've been planning to support Swift `Codable` types as well but haven't gotten around it yet, sorry. I wanted to provide a way to specify the encoder type (e.g. `JSONEncoder` or `PropertyListEncoder`), but some parts of `Transformable` may need rethinking because encoders don't have a common protocol, so we need to pass in an instance. I'll bump this in my priority, in the meantime you can use `NSArray` and `NSDictionary`, which is what CoreData originally supports (through objc bridging). It might not have binary compatibility with the future `Codable` though.
Author
Owner

@kevinrenskers commented on GitHub (Oct 25, 2017):

Thanks works fine for now, thanks!

@kevinrenskers commented on GitHub (Oct 25, 2017): Thanks works fine for now, thanks!
Author
Owner

@bluepixeltech commented on GitHub (Nov 25, 2020):

How do I CoreStoreObject class field with NSArray field?

@bluepixeltech commented on GitHub (Nov 25, 2020): How do I CoreStoreObject class field with NSArray field?
Author
Owner

@JohnEstropia commented on GitHub (Nov 26, 2020):

@bluepixeltech I'm assuming you are using the @Field types now, in which case you can use @Field.Coded for codable arrays or dictionaries. See https://github.com/JohnEstropia/CoreStore#fieldcoded

@JohnEstropia commented on GitHub (Nov 26, 2020): @bluepixeltech I'm assuming you are using the `@Field` types now, in which case you can use `@Field.Coded` for codable arrays or dictionaries. See https://github.com/JohnEstropia/CoreStore#fieldcoded
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#180