从 Swift 2 迁移到 Swift 3 期间的奇怪问题:初始化程序的参数名称与协议要求的参数名称不同

Weird issue during migration from Swift 2 to Swift 3: Initializer has different argument names from those required by protocol

我正在尝试将此 (https://github.com/emilwojtaszek/leveldb-swift) 项目从 Swift 2 迁移到 Swift 3。我已经清除了迁移过程中的所有 100 多个错误,但以下错误除外:

Initializer 'init(bytes:count:)' has different argument names from those required by protocol 'KeyType' ('init(bytes:length:)')

过去几个小时我一直在努力找出它的原因,但不知道问题出在哪里,有什么想法吗?

P.S.

这里是 link 项目的当前迁移状态:

https://drive.google.com/file/d/1pR6-NrJFYGOwYyLLg_SbYNCQ9lyF6Ljc/view?usp=sharing

问题截图如下:

在 Swift 2 中,我们曾经使用带有初始值设定项 init(bytes:length:). Since Apple has done a lot of renaming in Swift 3, NSData is called Data and the initializer is called init(bytes:count:) 的 NSData。

所以您需要做的就是更新您的 KeyType 协议:

public protocol KeyType {
    init(bytes: UnsafeRawPointer, count: Int) // change "length" to "count"
    func withSlice(_ f: (Slice) -> ())
    func asData() -> Data
}