出现这种错误可能因为类名跟函数名冲突,特别是在出现代理的时候,例如
#import <UIKit/UIKit.h>
@class UCSPasswordView;
@protocol UCSPasswordViewDelegate <NSObject>
#pragma mark - 输入完回掉
- (void)UCSPasswordView:(UCSPasswordView *)passwordView withPassword:(id)password;
#pragma mark-- 输入不符合格式的
@end
@interface UCSPasswordView : UIView
@property (nonatomic,weak) id<UCSPasswordViewDelegate> delegate;
@end
用swift遵守上面OC写的协议时肯定在在swift处报use of undeclared type ***错。因为Delegate里面的方法UCSPasswordView跟类名UCSPasswordView冲突了。以下这句话引自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.
当Swift代码遇到use of undeclared type错误,可能是类名与协议方法名冲突导致。例如,OC的UCSPasswordViewDelegate协议中,'UCSPasswordView'方法名与类名相同,造成冲突。在Swift里,可以调整方法名避免冲突或使用别名来解决此问题。
2523

被折叠的 条评论
为什么被折叠?



