0

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?

M.K.
  • 29
  • 1
  • 8
  • 1
    Did you read [How to call Objective-C code from Swift](https://stackoverflow.com/questions/24002369/how-to-call-objective-c-code-from-swift)? – Martin R May 28 '17 at 14:42

2 Answers2

2

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! :)

Dominik Bucher
  • 2,120
  • 2
  • 16
  • 25
0

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.

Yafi
  • 81
  • 1
  • 4