【问题标题】:Use of unresolved identifier 'DefaultConflictHandlers'使用未解决的标识符“DefaultConflictHandlers”
【发布时间】:2019-03-12 14:37:31
【问题描述】:

我正在关注 MongoDB 提供的 Build a Mobile App With Sync 教程,但在特定集合上配置同步时遇到错误。这是我的代码:

todoCollection.sync.configure(
    conflictHandler: DefaultConflictHandlers.remoteWins.resolveConflict,
    changeEventDelegate: { documentId, event in
        if !event.hasUncommittedWrites {
            // you can add code here to update your app's UI or
            // perform other operations based on a document change.
        }
}, errorListener: self.on)

这些是我的导入:

import MongoSwift
import StitchCore
import StitchRemoteMongoDBService

为了清楚起见,这里是错误:

我有一些理论,比如需要单独导入,或者我的 XCode 索引刚刚损坏,但到目前为止没有成功。

编辑:我正在使用pod 'StitchSDK', '~> 5.0.0'

【问题讨论】:

    标签: swift mongodb mongodb-stitch


    【解决方案1】:

    我已经安装了那个 pod,发现你需要添加

    import StitchCoreRemoteMongoDBService
    

    DefaultConflictHandlers 被重命名为DefaultConflictHandler

    所以在导入你的代码后会是:

    todoCollection.sync.configure(
        conflictHandler: DefaultConflictHandler.remoteWins.resolveConflict,
        changeEventDelegate: { documentId, event in
            if !event.hasUncommittedWrites {
                // you can add code here to update your app's UI or
                // perform other operations based on a document change.
            }
    }, errorListener: self.on)
    

    【讨论】:

    • 是的 import 消除了错误,但是新的方法调用看起来像这样:DefaultConflictHandler<TodoItem>.remoteWins() 现在一切运行顺利,谢谢。
    猜你喜欢
    • 2018-03-29
    • 2019-05-01
    • 2016-06-27
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    相关资源
    最近更新 更多