1

Hi everyone,

I'm working with Realm and I'd like to add an NSArray as one of my RLMObject's properties.

I just want to store NSString in that Array, that's why I don't want to define a RLMArray property ( I don't want to create a new RLMObject equivalent to an NSString ).

Is there a way to do that ?

Thanks in advance.

2 Answers 2

2

Joe from Realm here. Currently we don't support Arrays of primitive types. It is something that we are discussing and on the road map though.

For now your best bet will be to create another RLMObject and then an RLMArray relationship to that, to store your primitive types.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Joe, great job by the way !
Please update this answer as per Realm-Cocoa 3.0.0 if you still work for Realm :D
1

We have implemented this by making a RLMString class.

One problem we have had is that we would get orphaned values in the database, but it was probably due to the way we saved our data. This could probably be handled by using the stringValue as the key for the RLMObject.

This is our Swift implementation:

import Foundation
import Realm

class RLMString: RLMObject {
    dynamic var stringValue: String = ""

    init(stringValue: String) {
        self.stringValue = stringValue
        super.init()
    }

    override init() {
        super.init()
    }
}

4 Comments

Thank you Leif, I'll keep using Realm. I really think it's the best way to manage database ( on iOS at least ).
I agree with you @Randy - it is a really nice database! I will start using it other apps as well, and maybe for WatchApp as well.
@LeifBredgaardHonorė, How can we convert that RLMString back to NSString? I tried doing rlmStringObj.stringValue but it gives me an error
@JiteshW sorry did not see your comment till now :) That should be the correct way to it though, given you have added the RLMString class and stored it in your realm. Could you try to post a sample of what you do please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.