了解为什么 Xcode 中的“类型不符合协议”(swift)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36872667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:45:45  来源:igfitidea点击:

see why "type does not conform to protocol" in Xcode (swift)

iosxcodeswiftswift-protocols

提问by Quintana

I frequently have relatively complicated protocols with associatedType constraints, are used in generics, are used by CoreData type extensions, etc. I therefore relatively frequently get the error: Type .. does not conform to protocol .... I usually can figure this out after a while, but the error message is really unhelpful -- and usually, if the problem is a minor typo in the signature of a method or something, the bug takes a little while to find. With Java interfaces, IDEs will often report something like method ... not implementedor something, so I know which method to look at in closer detail.

我经常有相对复杂的具有关联类型约束的协议,用于泛型,被 CoreData 类型扩展使用等。因此我相对频繁地得到错误:Type .. does not conform to protocol ...。我通常可以在一段时间后解决这个问题,但错误消息确实没有帮助——而且通常,如果问题是方法签名中的小错误或其他东西,则需要一段时间才能找到错误。对于 Java 接口,IDE 经常会报告类似的内容method ... not implemented,因此我知道要更详细地查看哪种方法。

is there a way to make Xcode report details about the members of the protocol which are missing from the conforming type?

有没有办法让 Xcode 报告有关符合类型中缺少的协议成员的详细信息?

回答by Michael Peterson

When you get that error, click on the arrow to expand it. It will show the required function(s) that are missing.

当您收到该错误时,单击箭头将其展开。它将显示缺少的所需功能。

Here is an example where I implement UITableViewDataSource but I have forgot to provide the "cellForRowAtIndexPath" function.

这是我实现 UITableViewDataSource 但我忘记提供“cellForRowAtIndexPath”函数的示例。

enter image description here

在此处输入图片说明