关于swift中出现 use of undeclared type ***错误的一种解决方法

当Swift代码遇到use of undeclared type错误,可能是类名与协议方法名冲突导致。例如,OC的UCSPasswordViewDelegate协议中,'UCSPasswordView'方法名与类名相同,造成冲突。在Swift里,可以调整方法名避免冲突或使用别名来解决此问题。

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


#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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值