WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

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 Fernando Olivares

SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!

Read the book

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.