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

来源:互联网 发布:中软国际java面试题 编辑:程序博客网 时间:2024/06/05 19:44

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

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

例如

#import <UIKit/UIKit.h>@class CustomSearchBar;@protocol CustomsearchResultsUpdater <NSObject>@required/**第一步根据输入的字符检索 必须实现*/-(void)CustomSearch:(CustomSearchBar *)searchBar inputText:(NSString *)inputText;@end@interface CustomSearchBar : UIView@property (nonatomic, weak) id<CustomsearchResultsUpdater>  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.

如有问题可添加我的QQ1290925041

还可添加QQ:234812704(洲洲哥学院)

欢迎各位一块学习,提高逼格!

也可以添加洲洲哥的微信公众号


更多消息

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

0 0
原创粉丝点击