Swift中出现 use of undeclared type ***Delegate错误的解决方法

本文首发地址
出现这种错误可能因为类名跟函数名冲突,特别是在出现代理的时候,

这个错误,你会发现真的很难找,只要不是会用代理就没问题,一调用代理就提示你找不到
use of undeclared type ***Delegate这问题。为什么说头疼,Swift调用OC的,oc的代码都是好好都是按照格式来的,没问题。Swift中你写的也对,绝对没问题。哎。。。

例如

#import 
@class CustomSearchBar;

@protocol CustomsearchResultsUpdater 

@required
/**第一步根据输入的字符检索 必须实现*/
-(void)CustomSearch:(CustomSearchBar *)searchBar inputText:(NSString *)inputText;
@end


@interface CustomSearchBar : UIView
@property (nonatomic, weak) id  searchResultsUpdater;
@end

用Swift遵守上面OC写的协议时肯定在在swift处报use of undeclared type ***错。因为Delegate里面的方法CustomSearchBar跟类名CustomSearchBar冲突了。以下这句话引自stackoverflow的回答:(http://stackoverflow.com/questions/24627598/use-of-undeclared-type-in-swift-project)

Your delegate function name is VKConnector and you also have a class named VKConnector. That's your conflict. In Objective C your delegate method is VKConnector:withBool: but in Swift it's simply VKConnector and withBool is not a part of the name.

如有问题可添加我的QQ:1290925041
还可添加QQ群:234812704(洲洲哥学院)
欢迎各位一块学习,提高逼格!
也可以添加洲洲哥的微信公众号

更多消息

更多信iOS开发信息 请以关注洲洲哥 的微信公众号,不定期有干货推送:

Swift中出现 use of undeclared type ***Delegate错误的解决方法_第1张图片
这里写图片描述

你可能感兴趣的:(Swift中出现 use of undeclared type ***Delegate错误的解决方法)