4

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

cmacera
  • 1,140
  • 1
  • 10
  • 21

3 Answers3

4

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.

cmacera
  • 1,140
  • 1
  • 10
  • 21
3

You probably forgot to launch Mac demo app first or login with a different user. The tutorial assumes that existing data will be synced at login. If you have never launched the Mac app or logged in a different user, it may happen that items are not managed by Realm.

The tutorial says the following:

First, please follow the Get Started instructions to get set up with the Realm Mobile Platform and to launch the macOS version of RealmTasks.

Also, you attempt to try this tutorial with ROS on AWS. The tutorial assumes running ROS on a same local machine.

So you should modify the Mac app code to connect to the AWS, then run it to synchronize the initial data. Then run the tutorial iOS app.

kishikawa katsumi
  • 10,418
  • 1
  • 41
  • 53
  • @katsumi, you are right, the problem was that there is no TaskList initialized because I did not follow the Get Started instructions. But I do not want to use the desktop app, just mobile, so I have just modified the updatedList function to create a TaskList if does not exist any. Thanks again! – cmacera Jan 30 '17 at 09:31
0

The default permissions here show whether all other users can access the Realm or not, which isn't the case here. We already have an internal issue around clarifying this.

The registered user who owns the Realm has individual permissions to it by default. If you wouldn't have permissions opening the synchronized Realm from the client would also fail because of insufficient permissions, so this isn't the problem here.

So going back to your code:

try! items.realm?.write { … }

My guess would be that the problem here is that the collection isn't already attached to a Realm, so that items.realm? evaluates to null. In that case the write transaction wouldn't be executed. You can resolve this by making sure to add the items first to a Realm or executing the write directly on a synchronized Realm.

marius
  • 7,766
  • 18
  • 30
  • Thanks for answering @marius, I am new to swift and I do not follow you... the items seems to have a realm property, I have updated my question with an image. – cmacera Jan 25 '17 at 15:31
  • 1
    From your output I can recognize that there is a `realm` property on your view controller. It doesn't seem though like your items list is Realm backed. You can try to change `items.realm?` to `items.realm!`, then it would fail but not silently. The real question though is why this happens. Could you share some more code and show where you initialize the `items` property? – marius Jan 25 '17 at 16:20
  • If you open this link: [link](https://realm.io/docs/tutorials/realmtasks/) you could see all my code (I prefer not to paste here), I have followed the tutorial step by step because I am starting with swift. Maybe the tutorial is outdate or has a bug that I can not see – cmacera Jan 25 '17 at 16:52
  • 1
    Please see Katsumi's answer above, the tutorial relies on seeding the Realm from Mac app with initial data as a simplification, which breaks in your case. If that still shouldn't resolve it, you might want to check out the full project to the tutorial which is up [in a branch of our example repository](https://github.com/realm/realm-sync-demos/tree/ians-edits/RealmTasksTutorial). – marius Jan 27 '17 at 12:38