Weird issue during migration from Swift 2 to Swift

2019-05-30 00:21发布

I'm trying to migrate this (https://github.com/emilwojtaszek/leveldb-swift) project from Swift 2 to Swift 3. I've cleared all 100+ errors during migration except this following one:

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

I was struggling to figure out the reason for it past couple of hours and getting no clue of what the problem is, any thoughts?

P.S.

Here is the link to project with current state of migration:

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

Here is an screenshot of the problem:

enter image description here

1条回答
甜甜的少女心
2楼-- · 2019-05-30 00:58

In Swift 2 we used to have NSData with the initializer 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:) now.

So everything you need to do is to update your KeyType protocol:

public protocol KeyType {
    init(bytes: UnsafeRawPointer, count: Int) // change "length" to "count"
    func withSlice(_ f: (Slice) -> ())
    func asData() -> Data
}
查看更多
登录 后发表回答