[英]iOS - Using Cocoapods objective-C within Swift Code
I'm trying to add an objective-C/CocoaPods code ( GBFlatButton ) to an existing swift code. 我正在尝试将Objective-C / CocoaPods代码( GBFlatButton )添加到现有的swift代码中。 I read all about I found regarding Header settings and I did this, let me know if is well performed.
我阅读了关于标题设置的所有内容,我做了这个,让我知道是否表现良好。
Header Bridging configuration 标头桥接配置
Also the Header file has the right import files added to it. 此外,Header文件还添加了正确的导入文件。
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import <UIKit/UIKit.h>
#import <GBFlatButton/GBFlatButton.h>
#import <GBFlatButton/UIColor+GBFlatButton.h>
On the other hand the CocoaPods project doesn't give me an error when I compile the code. 另一方面,CocoaPods项目在编译代码时没有给出错误。 The error occurs when I use the button, maybe is the way I'm trying to use this objective-c code:
当我使用按钮时发生错误,也许是我尝试使用此Objective-c代码的方式:
let MyButton: GBFlatButton! = GBFlatButton(frame: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 40.0))
Also I tried to use it like this: @IBOutlet var FButton: GBFlatButton!
我也尝试使用它:
@IBOutlet var FButton: GBFlatButton!
This is the final error I have: 这是我的最后一个错误:
/Users//Documents/Projects/party/party/party/partyStepViewController.swift:18:19: Use of undeclared type 'GBFlatButton'
/Users//Documents/Projects/party/party/party/partyStepViewController.swift:18:19:使用未声明的类型'GBFlatButton'
/Users//Documents/Projects/party/party/party/partyStepViewController.swift:18:9: Could not infer type for 'MyButton'
/Users//Documents/Projects/party/party/party/partyStepViewController.swift:18:9:无法推断'MyButton'的类型
Any clue will help :) 任何线索都会有所帮助:)
Thanks!!, if you need more info don't hesitate to ask me. 谢谢!!,如果您需要更多信息,请不要犹豫,问我。
you forgot to add the bridging header in the Build settings of the app 你忘了在应用程序的Build设置中添加桥接头
In ViewController: 在ViewController中:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button: GBFlatButton! = GBFlatButton(frame: CGRectMake(0, 0, 200, 50))
self.view.addSubview(button)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
just do this and then it will work 只是这样做然后它会工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.