2015-06-09 47 views
1

內使用的CocoaPods目標-C我想一個Objective-C /的CocoaPods代碼(GBFlatButton)添加到現有的SWIFT代碼。我閱讀所有關於我發現關於標題的設置,我沒有這一點,讓我知道,如果很好地執行。iOS版 - 斯威夫特代碼

Header Bridging configuration

而且頭文件中添加了正確的導入文件。

// 
// 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> 

在另一方面,當我編譯代碼的CocoaPods項目不會給我一個錯誤。出現該錯誤,當我使用按鈕,也許是我想利用這個Objective-C代碼的方式:

let MyButton: GBFlatButton! = GBFlatButton(frame: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 40.0)) 

而且我試圖用這樣的:@IBOutlet var FButton: GBFlatButton!

這是最後的錯誤我:

/Users//Documents/Projects/party/party/party/partyStepViewController.swift:18:19: 使用未聲明的類型 'GBFlatButton'

///用戶的文件S /項目/方/方/方/ partyStepViewController.swift:18:9: 無法推斷 'myButton的'

任何線索將幫助:)

謝謝!類型,如果您需要更多信息請不要猶豫,問我。

+0

我添加以下代碼SWIFT代碼裏面:進口GBFlatButton。這工作正常。謝謝!! –

回答

3

你忘了加上橋接報頭在應用

enter image description here

在視圖控制器的生成設置:

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. 
    } 
} 

只是這樣做,然後它會工作

+0

偉大工程!謝謝 –