< unknown>:0:错误:类型'Key'限制为非协议类型'String' [英] <unknown>:0: error: type 'Key' constrained to non-protocol type 'String'

查看:210
本文介绍了< unknown>:0:错误:类型'Key'限制为非协议类型'String'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从2.3迁移到Swift 3并遇到了这个问题.该错误可追溯到视图控制器.

Migrating to Swift 3 from 2.3 and am running into this issue. The error is traceable to a view controller.

我没有看到任何需要将键"限制为字符串"的扩展名/协议.

I do not see any extensions/protocols which would require a 'Key' constrained to 'String'.

我试图注释掉可能导致该错误的代码,并且得到了奇怪的结果-即,删除一个空的viewDidLoad()会使该错误出现在另一个类中.

I've tried to comment out code that might be causing the error, and have had strange results - ie removing an empty viewDidLoad() made the error appear in another class.

如果取得进展,我将更新线程.

I'll update the thread if I make progress.

推荐答案

键是结构内部的类型,例如字典之类的struct/class.

Key is a type inside a structure maybe a struct/class like Dictionary.

如果在字典中,请使用AnyHashable作为键替换String.

Use AnyHashable as Key to replace String if in Dictionary.

这篇关于< unknown>:0:错误:类型'Key'限制为非协议类型'String'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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