简体   繁体   English

在Xcode中看到为什么“类型不符合协议”(swift)

[英]see why “type does not conform to protocol” in Xcode (swift)

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 ... . 我经常有相对复杂的协议与associatedType约束,用于泛型,由CoreData类型扩展使用等。因此我经常得到错误: 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. 我通常可以在一段时间后弄清楚这一点,但错误信息实际上是无益的 - 通常,如果问题是方法或某事的签名中的一个小错误,则该bug需要一段时间才能找到。 With Java interfaces, IDEs will often report something like method ... not implemented or something, so I know which method to look at in closer detail. 使用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报告有关协议成员的详细信息?

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”函数。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM