从Swift 2迁移到Swift 3的奇怪问题:初始化程序的参数名称与协议要求的参数名称不同 [英] Weird issue during migration from Swift 2 to Swift 3: Initializer has different argument names from those required by protocol

查看:191
本文介绍了从Swift 2迁移到Swift 3的奇怪问题:初始化程序的参数名称与协议要求的参数名称不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

推荐答案

在Swift 2中,我们曾经使用带有初始化程序

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.

因此,您需要做的就是更新KeyType协议:

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
}

这篇关于从Swift 2迁移到Swift 3的奇怪问题:初始化程序的参数名称与协议要求的参数名称不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆