Ios 在swift中调用objective-c方法时崩溃

Ios 在swift中调用objective-c方法时崩溃,ios,objective-c,swift,Ios,Objective C,Swift,以下是事故信息: LMAlertView是一个由三部分组成的使用objective-c,我使用它很长时间了,一切都很顺利。但是当我在swift中使用它时,发生了一些奇怪的事情:当我编写init时,Xcode为我发出警报,我只需点击enter键,整个函数就自动完成了。但是Xcode显示的函数不是LMAlertView中真正的函数: 以下是LMAlertView中的源代码: -(id)initWithTitle:(NSString*)标题消息:(NSString*)消息委托:(id)委托取消按

以下是事故信息:

LMAlertView
是一个由三部分组成的使用objective-c,我使用它很长时间了,一切都很顺利。但是当我在swift中使用它时,发生了一些奇怪的事情:当我编写
init
时,Xcode为我发出警报,我只需点击enter键,整个函数就自动完成了。但是Xcode显示的函数不是LMAlertView中真正的函数:

以下是LMAlertView中的源代码:


-(id)initWithTitle:(NSString*)标题消息:(NSString*)消息委托:(id)委托取消按钮提示:(NSString*)取消按钮提示其他按钮提示:(NSString*)其他按钮提示。。。NS_要求_NIL_终止;

如您所见,参数
otherbuttonitles
在我的代码中丢失,该代码使用Xcode自动完成

如果我在代码中添加
otherbuttonitles
参数,它将生成失败

我该如何解决这个问题?如果有人能解释一下,那就太好了。

在Swift中,试一下

let alertView = LMAlertView(title: "YourTitle",message:"your Message" delegate:nil cancelButtonTitle:"cancel" otherButtonTitles:nil)

您需要更改LMAlertView的源代码

首先在LMAlertView.h中,添加一个新的init方法,并为其他标题添加一个数组(别忘了注释旧标题):

Second在LMAlertView.m中,实现新的init方法(不要忘记注释旧方法):

最后,您可以像这样用swift调用它,而不会发生崩溃:

let alertView = LMAlertView(title: "a title", message: "a message", delegate: self, cancelButtonTitle: "cancel", otherButtonTitles: ["other title1","other title2"])
//......

修复它,插入“,”,我做了,然后Xcode显示:“表达式的类型在没有更多上下文的情况下是不明确的”请看看这个我不知道为什么Xcode没有给我完整的函数警报信息。你在桥接头中添加了LMAlertView吗?这个项目用oc编写,我在PCH文件中导入“LMAlertView.h”,在桥接文件中,我导入PCH文件。
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles {
    self = [super init];
    if (self) {
        _delegate = delegate;
        [self setupWithTitle:title message:message cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles];
    }
    return self;
}
let alertView = LMAlertView(title: "a title", message: "a message", delegate: self, cancelButtonTitle: "cancel", otherButtonTitles: ["other title1","other title2"])
//......