2

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> 
}
Alan
  • 9,331
  • 14
  • 52
  • 97

2 Answers2

3

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>()
}
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
-1

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

Tob
  • 985
  • 1
  • 10
  • 26