Ios &引用;找不到初始值设定项“;在Swift中使用Objective-C类时
第一次创建swift应用程序时,它运行良好,直到我在尝试将Objective-C类用于swift ViewController时遇到问题 Objective-C类初始化(RKDropdownAlert.h) 我的尝试:Ios &引用;找不到初始值设定项“;在Swift中使用Objective-C类时,ios,swift,Ios,Swift,第一次创建swift应用程序时,它运行良好,直到我在尝试将Objective-C类用于swift ViewController时遇到问题 Objective-C类初始化(RKDropdownAlert.h) 我的尝试: var alert: RKDropdownAlert = RKDropdownAlert(title:"Error", message:"Please enter valid credentials.", backgroundColor:UIColor.redColor(), t
var alert: RKDropdownAlert = RKDropdownAlert(title:"Error", message:"Please enter valid credentials.", backgroundColor:UIColor.redColor(), textColor:UIColor.whiteColor(), time:3)
错误:找不到初始值设定项
我以前如何使用目标C中的课程:
[RKDropdownAlert title:@"Error: Invalid Characters!" message:@"Please remove special characters from the field." backgroundColor:[UIColor redColor] textColor:[UIColor whiteColor] time:3];
我已经看了一个多小时了。有人能帮忙吗?谢谢 因为这是一个类方法而不是初始值设定项,所以必须使用
RKDropdownAlert.title(title:NSString, message:NSString, ...)
如果要使该方法成为初始值设定项,则必须将Objective-C文件中的方法声明更改为
-(instancetype)initWithTitle:(NSString*)title message:(NSString*)message backgroundColor:(UIColor*)backgroundColor textColor:(UIColor*)textColor time:(NSInteger)seconds;
在实施过程中:
-(instancetype)initWithTitle:(NSString*)title message:(NSString*)message backgroundColor:(UIColor*)backgroundColor textColor:(UIColor*)textColor time:(NSInteger)seconds
{
self = [super init];
if (self) {
//Create your alert here
}
return self;
}
类方法应该可以,只要名称遵循正确的模式,即
+alertWithTitle:message:…
-(instancetype)initWithTitle:(NSString*)title message:(NSString*)message backgroundColor:(UIColor*)backgroundColor textColor:(UIColor*)textColor time:(NSInteger)seconds
{
self = [super init];
if (self) {
//Create your alert here
}
return self;
}