ObjectID?

205 views
Skip to first unread message

Calvin Tam Wah Kit

unread,
Jul 16, 2014, 1:52:15 PM7/16/14
to realm...@googlegroups.com
Is there a way to get an object's ID? I am trying to transition my existing code from Coredata to realm, and it's quite reliant on objectIDs to query. 

Alexander Stigsen

unread,
Jul 16, 2014, 2:00:44 PM7/16/14
to Calvin Tam Wah Kit, realm-users
Objects in Realm does not have an object ID (they don't need any since relations are not join based). If you need object ID's in your queries, the recommended way to do it is just to add a property to the object with a value you can use as ID.

We know that many applications have been designed around the availability of Object ID's, so we will be adding an ID property type with an automatic unique id. It is on the roadmap.


On Wed, Jul 16, 2014 at 10:52 AM, Calvin Tam Wah Kit <wah...@gmail.com> wrote:
Is there a way to get an object's ID? I am trying to transition my existing code from Coredata to realm, and it's quite reliant on objectIDs to query. 

--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-users...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-users/5153e36a-598b-433b-afb8-81fd84df8717%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JP Simard

unread,
Jul 16, 2014, 2:18:07 PM7/16/14
to Alexander Stigsen, Calvin Tam Wah Kit, realm-users
Alex is right. Here’s an example of how you could add an objectID property to your models:

@interface Person : RLMObject
// ObjectID property
@property NSString *objectID;
// Model properties
@property NSString *name;
// etc...
@end

// Elsewhere
RLMRealm *realm = self.realmWithTestPath;
[realm beginWriteTransaction];
Person *mary = [Person new];
mary.name = @"mary";
mary.objectID = [[NSUUID UUID] stringValue];
[realm commitWriteTransaction];

Calvin Tam Wah Kit

unread,
Jul 16, 2014, 10:52:26 PM7/16/14
to realm...@googlegroups.com
Thanks guys, this have been really helpful. I looked up on NSUUID, seems like its quite reliable for now to create unique IDs. Looking forward for an official one tho.

Overall I am really impressed with Realm, it really is much easier than Coredata. Great job guys!

Tim Anglade

unread,
Jul 16, 2014, 10:55:46 PM7/16/14
to Calvin Tam Wah Kit, realm...@googlegroups.com
Thank you Calvin! Keep the questions coming :)


--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-users...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.

Zsombor Papp

unread,
Mar 12, 2015, 11:49:32 PM3/12/15
to realm...@googlegroups.com, a...@realm.io, wah...@gmail.com, realm...@googlegroups.com
Do you happen to have an update on when this unique ID feature (or at least auto-incrementing fields) might be available?

In the meantime: where is it documented that multiple calls to [NSUUID UUID] is guaranteed to return unique values?

Thanks,
Zsombor

Joe Anderson

unread,
Mar 13, 2015, 1:01:58 PM3/13/15
to Zsombor Papp, a...@realm.io, wah...@gmail.com, realm...@googlegroups.com, realm...@googlegroups.com
Hi Zsombor,

We are still considering the way we want to approach it, keeping in mind sync across all devices, so there are no updates for right now. You can check out this article here to learn more about the guaranteed unique values from UUID.

--
Joe Anderson



To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa...@googlegroups.com.

To post to this group, send email to realm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



{#HS:77518351-678#}

Zsombor Papp

unread,
Mar 13, 2015, 1:28:34 PM3/13/15
to realm...@googlegroups.com, zsombo...@gmail.com, a...@realm.io, wah...@gmail.com, realm...@googlegroups.com, he...@realm.io
Thanks Joe.

Could you please quote here the relevant part of that NSHipster article? As far as I can tell it doesn't address the problem of multiple calls to [NSUUID UUID] always returning unique values. The closest it comes is this: "a sequence of 128 bits that can guarantee uniqueness across space and time", which is a direct quote from the RFC and doesn't say anything about the implementation of [NSUUID UUID].

Joe Anderson

unread,
Mar 13, 2015, 1:38:21 PM3/13/15
to Zsombor Papp, realm...@googlegroups.com
No problem! That was the line I was referring to. I think you will have to dive deeper into that research article that is being referred. Apple's documentation refers to it as well

--
Joe Anderson
{#HS:77518351-678#}
Reply all
Reply to author
Forward
0 new messages