How do I create and use a realm?

ros

#1

I am busy experimenting with Realm and have a server instance running for sync purposes.

I created some classes with Realm Studio but could not edit them so I deleted the entire realm - yes the default realm. I then created a new realm called ‘default’ and created the classes but am unable to figure out how to connect to it.

I think a simple explanation for how to do this would be useful as all the examples seem to assume an existing default realm on the server - or something.

Can anyone provide a step by step guide to recreating the default realm on a server and the steps required by the client application for connecting to the server and getting a copy of the schema and existing database.

This seems like a relatively simple thing to have to do and yet I can’t seem to find any explanation of how to do this. Hopefully I am just not looking in the right place.

Thanks and apologies in advance if I missed something obvious.


#2

@duncan The /default realm is just a generic starting realm that we generate for you but you can certainly create a bunch of other realms and name them whatever you want. I’d recommend starting with our tutorial here;
https://docs.realm.io/platform/getting-started-1/ios-quick-start/step-1-my-first-realm-app

In it you will see that it creates a realm called /ToDo with this schema:

class Item: Object {
    
    @objc dynamic var itemId: String = UUID().uuidString
    @objc dynamic var body: String = ""
    @objc dynamic var isDone: Bool = false
    @objc dynamic var timestamp: Date = Date()

The schema gets created because the user (by default an admin privileges) opens a realm to that server with that schema.

If you do not want to go through the tutorial step by step you can clone the tutorial here and start playing around: