NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Trying to "translate" snippet of Objective-C code into SwiftUI

Forums > SwiftUI

I'm trying to incorporate iosMath into a project, but the instructions on how to create an instance of LaTeX-formatted text are in Obj-C:

#import "MTMathUILabel.h"

MTMathUILabel* label = [[MTMathUILabel alloc] init];
label.latex = @"x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}";

From what I can understand of the .h and .m files that comprise iosMath, MTMathUILabel is a UIView and latex is a property of MTMathUILabel.

Anyone able to Swiftify #, @, alloc and init or otherwise familiar with using iosMath?

   

Swift equivalent of the ObjC code is the easy part:

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

Additional subjects to learn:

  1. How to import a Cocoa Pod (iosMath) into your Xcode project.
  2. How to import an ObjC class (MTMathUILabel) into a Swift app.
  3. How to include a UIKit view (MTMathUILabel) in a SwiftUI view.

   

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.