2017-05-28 82 views
0

如何在iOS中使用Swift中的iosMath,因爲iosMath是用Objective C編寫的?或者有另一種方法來顯示數學公式與斯威夫特?在Swift中使用iosMath

+1

你讀過[如何從Swift調用Objective-C代碼](https://stackoverflow.com/questions/24002369/how-to-call-objective-c-code-from-swift)? –

回答

0

我必使這儘可能快:

1)安裝的CocoaPods(打開終端,寫sudo gem install cocoapods

2)從終端改變目錄到你的項目和init的CocoaPods和編輯podfile這樣的:

cd /ProjectFolder 
pod init 
nano podFile 

(打開podfile,在那裏你粘貼莢回購),應該是這樣的:

# Uncomment the next line to define a global platform for your project 
# platform :ios, '9.0' 

target 'mathExample' do 
    # Comment the next line if you're not using Swift and don't want to use dynam$ 
    use_frameworks! 

    # Pods for mathExample 

    pod 'iosMath' 

end 

保存podfile,並通過安裝:

pod install 

從現在開始,使用工作區文件,而不是項目文件。我們完成安裝,你需要對現在的莢...

現在有點棘手 - >您需要從項目中添加新的Objective-C文件(所以只需新建文件 - > Objective-C文件並選擇創建橋接頭),您可以刪除創建的文件(但不是BRIDGING HEADER)

從現在起,您可以像使用快速fr一樣使用Objective-C框架不要忘了將該框架導入你將要使用它的類:

import UIKit 
//Importing our module 
    import iosMath 


class ViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     print(iosMathVersionNumber) 
     // Do any additional setup after loading the view, typically from a nib. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 


} 

希望這有助於,希望快樂的編碼! :)

0

一般問題已經回答。 Check this question out

您只需在podfile中添加iosMath,只要您在podfile中有use_frameworks!,就不需要任何標題。簡單地說,在你的swift文件中導入iosMath,你很好。