【问题标题】:Realm iOS Tutorial, Build iOS app from scratch, write failedRealm iOS 教程,从头开始构建 iOS 应用,编写失败
【发布时间】:2017-10-26 13:42:04
【问题描述】:

我已逐步按照领域网站上的“从头开始构建 iOS 应用”教程并观看了视频。一切似乎都井然有序。不幸的是,本教程不包含完整的源代码以供参考。

https://realm.io/docs/tutorials/realmtasks/

当我运行项目时,它会连接到 ROS 并毫无问题地创建领域。我可以在领域浏览器和网络浏览器中看到这一点。

但是,它立即开始抛出错误(在 Xcode 控制台中)。

realmTask[1000:40858] Sync: Connection[1]: Connected to endpoint '127.0.0.1:9080' 
realmTask[1000:40858] Sync: Connection[1]: Writing failed: End of input
realmTask[1000:40858] Sync: Connection[1]: Connection closed due to error

应用程序没有崩溃,错误一遍又一遍地重复,应用程序不会做任何事情。

这是我的设置代码。

func setupRealm() {
    // Log in existing user with username and password
    let username = "abcdefg"  
    let password = "1234"  

    SyncUser.logIn(with: .usernamePassword(username: username, password: password, register: false), server: URL(string: "http://127.0.0.1:9080")!) { user, error in
        guard let user = user else {
            fatalError(String(describing: error))
        }

        DispatchQueue.main.async {
            // Open Realm
            let configuration = Realm.Configuration(
                syncConfiguration: SyncConfiguration(user: user, realmURL: URL(string: "realm://127.0.0.1:9080/~/realmtasks")!)
            )
            self.realm = try! Realm(configuration: configuration)

            // Show initial tasks
            func updateList() {
                if self.items.realm == nil, let list = self.realm.objects(TaskList.self).first {
                    self.items = list.items
                }
                self.tableView.reloadData()
            }
            updateList()

            // Notify us when Realm changes
            self.notificationToken = self.realm.observe { _,_ in
                updateList()
            }
        }
    }
}

deinit {
    notificationToken?.invalidate()
}

【问题讨论】:

    标签: ios swift xcode realm


    【解决方案1】:

    对造成的混乱表示歉意;我们将尽快更新我们的教程。

    Realm Cocoa 3.* 需要使用通过 NPM 安装的 ROS 2.0(指令here)。我们网站上的 zip 文件中的 Realm Object Server 版本是 ROS 1.0,与 Realm Cocoa 3.* 不兼容。

    如果您想查看演示项目的完整源代码,可以查看其repository on GitHub。您可以克隆该存储库,安装其 CocoaPods,打开 Xcode 工作区,然后以这种方式从源代码构建项目。

    【讨论】:

      猜你喜欢
      • 2020-03-16
      • 1970-01-01
      • 2015-08-01
      • 2020-05-05
      • 2016-01-27
      • 2016-03-27
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      相关资源
      最近更新 更多