如何在swift中调用initWith …

我有一个Objective-c类(RDAlertView) ,它创build一个Alert(UIAlertView for ios <8和UIAlertController for ios> = 8)

这是Objective-C中的代码:

 RDAlertView* alert = [[RDAlertView alloc] initWithTitle:@"Notification" message:@"message" completion:completion:^(NSInteger buttonIndex, NSInteger cancelButtonIndex, NSArray *textflieds) { } cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; 

我的问题是:如何调用这个在Swift中没有任何改变我的课(如果可能的话)?

以下是示例项目的链接: https : //bitbucket.org/ejanowski/rdalertview-issue

我认为这是你需要的:

 var alert = RDAlertView(title: "Notification", message: "message", completion: nil, cancelButtonTitle: "OK", otherButtonTitles: nil) alert.show() 

希望它会有所帮助。

这些方法被视为构造函数。 你可以这样称呼他们:

 var alert = RDAlertView("notification", message:"message", completion:nil, cancelButtonTitle:"Cancel", otherButtonTitles:nil) alert.show() 

警告:没有IDE编写,注意语法错误/拼写错误

UIAlertView在iOS 8中已被弃用。

您可以使用此代码显示警报:

 var alert = UIAlertController(title: "Alert", message: "test", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) 
 UIAlertView.showWithTitle("Hello", message: "Hello World", cancelButtonTitle: "Okay") { alertView, buttonIndex in // Do something when the alert view is clicked let anAlertView = UIAlertView(title: "Choice", message: "Pick one", cancelButtonTitle: "No", otherButtonTitles: "Yes", "Maybe") anAlertView.showWithCompletion { alertView, buttonIndex in switch buttonIndex { case 1: println("Yes") case 2: println("Maybe") default: println("No") } }