Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to use Realm Object Server Tutorial

I have created an Amazon Web Services EC2 instance and deploy one of the AMIs with a Realm Object Server as its documentation explains: https://realm.io/docs/realm-object-server/#install-realm-object-server

Once installed and created my admin user, I have completed the iOS tutorial: https://realm.io/docs/tutorials/realmtasks/, just until point 7, enough for creating task, but when I add new task in app, nothing happens. Debugging, I notice that next sentence try, is not executing:

let items = self.items
try! items.realm?.write {
                items.insert(Task(value: ["text": text]), at: items.filter("completed = false").count)
            }

The items collection seems to be initialized properly:

enter image description here

In the ROS dashboard, can see the database referenced in Xcode: realm dashboard with sync path to referenced realm data base

In image can be see "Default permissions" property is no access, is this the reason of not creating new task? If so, how can I change that permissions? If that is not the reason, anyone could help me?

thanks in advance

like image 672
cmacera Avatar asked Mar 10 '23 01:03

cmacera


1 Answers

The problem was that I did not follow al the complete tutorial because I do not want to use the desktop application, just mobile example, but realm init objects in desktop app, so I never got a valid realm where perform actions.

For a quick and simple start with this realm tutorial pointing to an online server, not local, you must initialize the TaskList object and add it to self.realm on setup

            // Show initial tasks
            func updateList() {
                if self.realm.objects(TaskList.self).count == 0 {

                    let list = TaskList()
                    list.id = "000001"
                    list.text = "lista de prueba"

                    // Add to the Realm inside a transaction
                    try! self.realm.write {
                        self.realm.add(list)
                    }

                }
                if self.items.realm == nil, let list = self.realm.objects(TaskList.self).first {
                    self.items = list.items
                }
                self.tableView.reloadData()
            }

checking if there is not a TaskList with if self.realm.objects(TaskList.self).count == 0 {, you can create one and init realm.

like image 167
cmacera Avatar answered Mar 16 '23 14:03

cmacera