0

I am very new to app development, especially in iOS using Swift 3. For now, I want to display math formulas with swift using "iosMath". I followed the steps from this "Using iosMath in Swift" but I do not know what he means by creating a bridging header and don't know how to use iosMath in my code. For example, I want to enter a number and in the next line, the program shows the square root of the entered number. Here's an example of what I want to do:

import UIKit
import iosMath

class ViewController: UIViewController {

    @IBOutlet weak var numberField: UITextField!
    @IBOutlet weak var resultLabel: UILabel!

    @IBAction func computeTapped(_ sender: Any) {
        guard let numberValue = numberField.text else {
            return
        }

        let result = numberValue

        resultLabel.text = "The Square root of \(result) is \(result)"
        resultLabel.isHidden = false        
    }
}

Hope you can help me :) Thanks in advance!

TBH
  • 145
  • 1
  • 11

1 Answers1

2

If you already can import iosMath go to step2

Okay, to import iosMath you need to create a bridging header(however, my project imports iosMath without it, don't know why.) To create it just create a new objective-c file in your Project manilla folder 1st, when you create it, bridging header will be added automatically, now you can delete obj-c file, but not the bridging header, then build project and import iosMath module.

Step 2

Basically, iosMath is used to draw(display) mathematical equations like this:2nd

To create it:

let yourLabel: MTMathUILabel = MTMathUILabel()
yourLabel.latex = "x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}"
yourLabel.sizeToFit()

A program that you want will be like

 guard let numberValue = Int(numberField.text) else {
    return
 }
let result = numberValue
resultLabel.text = "The Square root of \(result) is \(result*result)"

And..

Bridging header is used to allow to access different classes by both languages(obj-c,swift).

If you accidentally delete the bridging header, go to build settings in your project, search 'bridging...' , select this line and press backspace![3d, after that repeat the steps to create bridging header.

PigeonPO
  • 74
  • 8
  • how to use NSAttributedString string in MTMathUILabel library. "yourLabel.latex = "x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}"" – Himanshu Patel Apr 06 '19 at 06:43
  • can you describe exactly how to import iosMath, since i don't really get it, and my bridging header can't find file "IosMath/IosMath.h" – glassomoss Feb 15 '20 at 16:42