Alan
Alan

Reputation: 9481

Storing a List of String Array in Realm

If I want to simply store an array of Strings in Realm, am I forced to wrap it in an custom class that extends Object?

Example:

class ExampleObject : Object {
   var stringArray : List<String> 
}

Upvotes: 2

Views: 1839

Answers (2)

EpicPandaForce
EpicPandaForce

Reputation: 81588

Not since Realm-Cocoa 3.0.0.

Loosen RLMArray and RLMResults's generic constraint from RLMObject to NSObject. This may result in having to add some casts to disambiguate types.

and

List can now contain values of types Bool, Int, Int8, Int16, Int32, Int64, Float, Double, String, Data, and Date (and optional versions of all of these) in addition to Object subclasses.

Querying Lists containing values other than Object subclasses is not yet implemented.

So following should just work:

class Student : Object {
    let stringArray = List<String>()
}

Upvotes: 3

Tob
Tob

Reputation: 1025

Realm does not support the native types. Take a look at this post for a demonstration of how to do it: Storing an array of strings using Realm's RLMArray

Upvotes: -1

Related Questions