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")
}
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")
}
```

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 :)
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.
@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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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:
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 :)@JohnEstropia commented on GitHub (Oct 25, 2017):
Transformercurrently only supportsNSCoding. I've been planning to support SwiftCodabletypes as well but haven't gotten around it yet, sorry. I wanted to provide a way to specify the encoder type (e.g.JSONEncoderorPropertyListEncoder), but some parts ofTransformablemay 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
NSArrayandNSDictionary, which is what CoreData originally supports (through objc bridging). It might not have binary compatibility with the futureCodablethough.@kevinrenskers commented on GitHub (Oct 25, 2017):
Thanks works fine for now, thanks!
@bluepixeltech commented on GitHub (Nov 25, 2020):
How do I CoreStoreObject class field with NSArray field?
@JohnEstropia commented on GitHub (Nov 26, 2020):
@bluepixeltech I'm assuming you are using the
@Fieldtypes now, in which case you can use@Field.Codedfor codable arrays or dictionaries. See https://github.com/JohnEstropia/CoreStore#fieldcoded