UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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?

1      

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.

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.