Using iosMath in Swift

前端 未结 2 850
鱼传尺愫
鱼传尺愫 2021-01-27 07:36

how can I use iosMath in Swift on iOS, because iosMath is written in Objective C? Or is there another way to display mathematical formulas with Swift?

相关标签:
2条回答
  • 2021-01-27 08:17

    I will make this as fast as possible:

    1.) install cocoaPods (open up terminal and write sudo gem install cocoapods)

    2.) From terminal change directory to your project and init cocoaPods and edit the Podfile like this:

    cd /ProjectFolder
    pod init
    nano podFile 
    

    (opens the podfile, where you paste the pod repo) , should look like this:

    # 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
    

    save podfile and install via:

    pod install
    

    from now, use the workspace file instead of the project file... We are done installing the pod you need right now...

    Now it gets a little bit tricky -> You need to add new Objective-C file into the project (so just New File -> Objective-C file and select create bridging header) from now, you can just delete the created file (BUT NOT THE BRIDGING HEADER)

    from now, you can use the Objective-C framework just as it was swift framework,don't forget to import that framework into classes you will use it:

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

    Hope this helps, wish happy coding! :)

    0 讨论(0)
  • 2021-01-27 08:26

    The general question has already been answered. Check this question out.

    All you have to do is add iosMath in your podfile and as long as you have use_frameworks! in the podfile, you won't need any headers. Simply, import iosMath in your swift file and you are good to go.

    0 讨论(0)
提交回复
热议问题