2017-05-28 24 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,你很好。