简体   繁体   中英

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 ... . 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 implemented or something, so I know which method to look at in closer detail.

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

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.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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