-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to store an array of strings in Realm? #3800
Comments
Found this: http://stackoverflow.com/a/31730894/5236819 Really wish Realm supported primitive types. :) Thanks anyways |
For others finding this, we're tracking it in #1120. |
We now support list of primitives. See https://realm.io/blog/realm-cocoa-reaches-3-0/ |
Thanks |
For some reason it doesn't work for me, I'm using ObjectMapper: Transform // Transform Array to Realm.List -> Primitives
func arrayToList<T>() -> TransformOf<List<T>, [T]> {
return TransformOf(
fromJSON: { (value: [T]?) -> List<T> in
let result = List<T>()
if let value = value {
result.append(objectsIn: value)
}
return result
},
toJSON: { (value: List<T>?) -> [T] in
var results = [T]()
if let value = value {
results.append(contentsOf: Array(value))
}
return results
})
} class Foo: Object, Mappable {
var images = List<String>()
public func mapping(map: Map) {
images <- (map["images.original"], arrayToList())
print(images) // <- At this point it has a value
...
}
But when I fetch those objects from Realm, |
Please don't ask questions that are only tangentially related to the initial question on an issue that's been closed for months. Your problem appears to be due to the fact that you're allocating a new |
Never mind, it works (even as |
what is the last code? |
@barylevy it works, the problem I had was on my own code |
I feel silly having to ask this question, but what's the best way to store an array or collection of strings? Without thinking, I originally tried to use a Swift array which crashed the app and I've also tried
List<String>
but because String is not a Realm type, it does not work. Suggestions?Just looking for a push in the right direction.
Cheers
The text was updated successfully, but these errors were encountered: