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

自作多情 提交于 2020-01-03 01:42:13

问题


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:


回答1:


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
}


来源:https://stackoverflow.com/questions/47662932/weird-issue-during-migration-from-swift-2-to-swift-3-initializer-has-different

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!