如何使用 swift 从 CDTReplicator 对象获取复制 ID?

How to get the replication ID from CDTReplicator object using swift?

我正在使用 Cloudant DB 并在 CDTReplicatorDelegate 中打印复制器对象的描述时,我看到它有一个唯一的复制会话 ID。如何使用该对象访问它?没有它的属性。

replicator.description 的示例输出:

CDTReplicator push, source: establishment, target: https://ighterequallockneovessin:*****@*****.cloudant.com/establishment filter name: (null), filter parameters (null), unique replication session ID: 930C1002-B0B2-4576-BE84-C0BEFBD00834

我将复制器对象(多个)存储在单个委托中,当复制完成时,我想删除它的引用。这就是我需要它的原因。

func appendReplicator(replicator: CDTReplicator) {
        replicators.append(replicator)
}

有什么想法吗?

目前你不能。这是故意的内部细节,如果您真的希望能够访问复制器会话 ID,最好的办法是在 github 上提出功能请求。

我正在为多个复制器使用一个委托。我只有两个复制器,所以当复制器启动时,我只是将对它的引用存储在这两个变量之一中。当它完成时,我将传递给 replicatorDidComplete 函数的复制器与那些变量进行比较。你能做这样的事情吗?

var replicators : [CDTReplicator] = []

// on start
replicators.append(replicator)

// on complete, error, etc
func replicatorDidComplete(replicator: CDTReplicator!) {
    var match: Int? = nil
    for (index,r) in replicators.enumerate() {
        if (r == replicator) {
            match = index
            break
        }
    }
    if (match != nil) {
        replicators.removeAtIndex(match!)
    }

我会将其移动到 removeReplicator 函数中,以便您可以从 replicatorDidCompletereplicatorDidError 等地方调用它