One of the strange limitations of Realm’s Database design is that it can’t seem to easily have members of primity properties like [String] or [Int]. Fortunately, all we have to do is to encapsulate it as a StringObject or an IntObject.

Let’s say we have a User object like so:

We’d like to have friendUserIds as a [String] to other UserIds. If you’ve read the documentation, it requires that collection types are of List<T:Object>. And since Object can’t be of a primitive String or Int (also others like Double, Float, etc…), we need to encapsulate by creating a utility class:

You can do this with Int, Double Bool, etc…

Now in our User Object we can add a List<StringObject member in. Our final code for User looks like:

Easy!

## Manipulating List<StringObject>();

List<Object> is a let type and can’t be replaced sadly. So you’ll have to call List<Object>‘s helper methods;

## Some Helper Extension Methods

You might want to add some Extension helpers to minimize the amount of code you write. I’ve personally added these extensions on the native String object and [String] to transform them into the StringObject type.

## Querying with NSPredicate

Querying is a little bit odd but it’s not too hard. If you’re using NSPredicate’s API you’ll need to specify a specific property aggregate query.
For example if you want to find the Users that is a friend equal to "max" then you’ll need to do this: