Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将条形码工具包Objective-C代码转换为Swift?_Objective C_Swift - Fatal编程技术网

如何将条形码工具包Objective-C代码转换为Swift?

如何将条形码工具包Objective-C代码转换为Swift?,objective-c,swift,Objective C,Swift,这是Objective-C代码: 如何将此代码转换为Swift 当我在Swift中尝试以下操作时,它说我无法将NSError传递到函数中 var error1 = NSError() BCKCode39Co = BCKCode39Co.init(content: Content, error: NSError?) 查看的标题,我建议您使用: 例如,在Swift 4.2中: do { let barcode = try BCKCode39Code.code39(withContent:

这是Objective-C代码:

如何将此代码转换为Swift

当我在Swift中尝试以下操作时,它说我无法将
NSError
传递到函数中

var error1 = NSError()

BCKCode39Co = BCKCode39Co.init(content: Content, error: NSError?)

查看的标题,我建议您使用:

例如,在Swift 4.2中:

do {
    let barcode = try BCKCode39Code.code39(withContent: string) // or use rendition with `withModulo43` parameter
    imageView.image = UIImage(barCode: barcode, options: nil)
} catch {
    print(error)
}

什么是
BCKCode39Co
@RobertDresler这是objective-c类。我在我的项目中使用这个类来生成条形码。请尝试
bckCode39Co=bckCode39Co(内容:您的文本,错误:&error1)
?thanx bro,在哪里可以找到此方法告诉我。因为这里有很多类,那么如何使用呢?我在查看时发现了这个。我选择了这个类方法,因为包含它会给Swift桥接带来问题。该行确实应该有一些指示,表明它在Swift中不可用(请参阅,它引入了
NS\u Swift\u UNAVAILABLE
),当您这样做时,Xcode可以正确地确定要调用的正确方法。完成后,您可以在github中执行类似于
let barcode=try BCKEAN8Code(内容:string)
.Thnx bro的pull-to-request操作。
+ (instancetype)code39WithContent:(NSString *)content error:(NSError *__autoreleasing *)error;
do {
    let barcode = try BCKCode39Code.code39(withContent: string) // or use rendition with `withModulo43` parameter
    imageView.image = UIImage(barCode: barcode, options: nil)
} catch {
    print(error)
}