I am interested in being able to type LaTeX to get formatted Math Output in my macOS projects. I have tried using the famous iosMath CocoaPod Library and also seen its working from their official examples Repository on GitHub. I am using Xcode 10, Swift 4.2 on macOS Mojave (10.14). Using the guidance given on the reply of this Question I was able to successfully incorporate the library and make it render Mathematical Text using latex in any iOS projects successfully. But it is giving great conflicts and problems in macOS. After Installing the CocoaPod in my own project successfully I tried to follow the paradigm given in their official macOS Example with several trials and errors but all resulting in failure.
I am describing whatever I tried as following:
As we can see, the example projects have used XIBs instead of Storyboards but when trying out the same code and mechanisms on iOS in Storyboards it works just fine.
As per guidance in their example projects I have tried Using a Custom View both on iOS and macOS (i.e. UIView and NSView respectively) and attached that custom view to the custom class MTMathUILabel in the Identity Inspector in Storyboard And then of course linked it to an IBOutlet of type MTMathUILabel in my code file. It works successfully in the case of iOS but fails in macOS Even When I use MTMathUIView Custom Class in the Identity Inspector of Storyboard.
In accordance to their macOS example File I typed similar code in my ViewController.Swift as given below:
var mathViewCode: MTMathUILabel = MTMathUILabel()
#IBOutlet weak var mathViewIB: MTMathUILabel!
override func viewDidLoad() {
super.viewDidLoad()
mathViewIB.latex = "\\lim_{x\\to\\infty}\\left(1 + \\frac{k}{x}\\right)^x = e^k"
mathViewCode.latex = "\\int_{-\\infty}^{\\infty} \\! e^{-x^2} dx = \\sqrt{\\pi}"
self.view.addSubview(mathViewCode)
}
When from the above code I execute only the programmatically called MTMathUILabel Variable Code then simply a blank window opens without any output in it. But when I try to use the IBOutlet Variable to print latex in the Custom NSView (whose Custom Class in Attributes Inspector has been set to MTMathUIView not MTMathUILabel because then it crashes) the app again opens with a blank window but this time with the following warning:
Failed to set (contentViewController) user defined inspected property
on (NSWindow): -[NSView setLatex:]: unrecognized selector sent to
instance 0x60000330d7c0
If in Storyboard's Identity Inspector for the Custom NSView I set the Custom Class to MTMathUIView then the Interface Builder Does not Crash but it doesn't work either and if I set it to MTMathUILabel then the Interface Builder Crashes with the following error:
IB Designables: Failed to render instance of MTMathUILabel: The agent
threw an exception.
However, in the above scenario (where the Storyboard's Custom NSView's Custom Class in Attributes Inspector has been set to MTMathUILabel) the app compiles successfully but throws the following run time error after crashing:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
As you can see, I have tried to follow the approaches given in their official macOS Sample Project but nothing works in my case even though their Sample Project successfully compiles and runs well in my Xcode.
Please help me with this iosMath Library because I really want to use it because of its Beautiful Output and great features or please suggest some other Math Library to type in LaTeX in my Mac Apps that really runs on macOS with Swift.
Huge Thanks In Advance!!
I ran into the same problem.
I don't have a solution, but it is possible to use iosMath with MacOs and
swift.
I created my Project LatexPic and added it to the original podfile. Now you can use it in macOS App in view controller like:
let latexlabel = MTMathUILabel()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
self.view.addSubview(latexlabel)
latexlabel.backgroundColor = .white
latexlabel.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
latexlabel.latex = "\\frac{2}{3}"
}
Podfile:
workspace 'iosMath.xcworkspace'
install! 'cocoapods', :deterministic_uuids => false
target 'iosMathExample' do
project 'iosMath.xcodeproj'
pod 'iosMath', :path => './'
end
target 'iosMathTests' do
project 'iosMath.xcodeproj'
pod 'iosMath', :path => './'
end
target 'MacOSMath' do
project 'MacOSMath.xcodeproj'
pod 'iosMath', :path => './'
end
target 'LatexPic' do
use_frameworks!
project 'LatexPic.xcodeproj'
pod 'iosMath', :path => './'
end
Related
I've been asked to update an existing macOS program, and have been given an Xcode project written in Swift 4.0. The program uses Cocoa to generate the interface programmatically.
I haven't used Swift (or Xcode) before and am unfamiliar with Cocoa, so I'm trying to pick it up as I go, but I was able to add a button to the interface with the following code:
public lazy var phaseInvertButton: NSButton = {
let button = NSButton()
self.addSubview(button)
return button
}()
However, when I tried to add a checkbox using the same code and an additional line,
button.setButtonType(NSSwitchButton), I got an error:
'NSSwitchButton' is unavailable in Swift.
I also tried creating it with
public lazy var phaseInvertButton: NSSwitchButton, but got the same error. According to the Cocoa documentation, NSSwitchButton is a subtype of NSButton, but I can't seem to get it working in Swift.
Can anyone enlighten me as to how I should create a checkbox programmatically in this context?
You can use:
let button = NSButton(checkboxWithTitle:"Title" target:nil action:nil)
If you want to stick with setting the button type of an NSButton, the type you want is .switch:
button.setButtonType(.switch)
I am a novice learning Swift and xcode by rewriting a code I originally developed in Javascript/PHP/MySql. I am working in macOS, using a storyboard in xcode as my basis for development. At the moment I am developing a SplitView. In the Master side I have an OutlineView. It has three levels, the outer two are expandable, and, until today, it worked just fine. All levels were populated, visible, and expandable where appropriate. I had Swift(4.0) and xcode (9.1) up-to-date as far as I know. So, today I decided it was time to update from Sierra to High Sierra. My master view has now gone completely blank. Nada. I tried to track the problem down and discovered, using the debugger in xcode, that the outlineView function in the NSOutlineViewDelegate extension to my MasterViewController is, apparently, not being called at all! I checked the Connections Inspector, and the connections to DataSource and Delegate are still intact. I searched online and found a few people with what seemed to be vaguely related recent problems associated with Cocoa bindings, but I could not connect their problem solution to mine since I am not using Cocoa bindings...it's on my list, but I am not there yet. The only thing I know that changed was going from Sierra to High Sierra. Any suggestions? Thanks!
ADDED: I now know a bit more about the problem.
Here is the code that works prior to High Sierra:
class ViewController: NSViewController {
#IBOutlet weak var webView: WebView!
#IBOutlet weak var outlineView: NSOutlineView!
var feeds = Feed
let dateFormatter = DateFormatter()
override func viewDidLoad() {
super.viewDidLoad()
dateFormatter.dateStyle = .short
if let filePath = Bundle.main.path(forResource: "Feeds", ofType: "plist") {
feeds = Feed.feedList(filePath)
print(feeds)
}
}
The code is taken from a tutorial on the OutlineView on the Ray_Wenderlich.com site. I patterned my code after this and both the tutorial and my code worked...until High Sierra. Apparently, until High Sierra, the system would spontaneously parse "feeds" and generate the outlineView display. With High Sierra the behavior changed and it no longer spontaneously produced the outlineView, neither in the tutorial nor my project. The result was a blank outLineView.
In a comment added to the tutorial, I now find that someone else had encountered the same behavior and suggested that the code now needed:
outlineView.reloadData(),
but my naive implementation of that suggestion simply generated a runtime error,
"[NSView reloadData]: unrecognized selector sent to instance"
Just make sure that when you start a new ‘Playground’ you have macOS as an application checked and not IOS. If you have IOS checked Swift will import UIKit (instead of Cocoa) which will cause your problem. GL.
In my Swift 2 project, targeting iOS 9.2 and above, in Xcode 8.2.1, I have code that shows the mail-compose screen like so:
if MFMailComposeViewController.canSendMail() {
let composeMailVC = MFMailComposeViewController()
composeMailVC.mailComposeDelegate = self
composeMailVC.setSubject("Test")
// etc
}
Originally I had a reference to the MessageUI.framework in my project properties, but after removing the framework reference and cleaning the project, it still builds fine and when I run the code on my device the mail compose window still appears and seems fully functional.
I cannot find any explicit references to MessageUI.framework in the raw text of my .xcodeproj file, nor is there anything in my Objective-C bridging header.
I know that Swift does make some implicit framework references, but I couldn't find anything that suggests MessageUI.framework is one of them.
Curiously when I jump to the definition of MFMailComposeViewController XCode shows it in the MessageUI module.
The compiler automatically added the frame work in given its previous direction - IE. Import.
I would like to use one of these two cocoapods, https://github.com/graycampbell/GCCalendar, and https://github.com/n8armstrong/CalendarView
I installed with pod install that went great. But when it comes to implementation I don't get it.
For GCCalendar it says "Create a subclass of GCCalendarViewController" and when I do that my Xcode turns red from errors. CalendarView docs say to use #IBOutlet weak var calendar: CalendarView! but when I do that I get errors. CalendarView! doesn't exist.
Can somebody explain what should I do to use CalendarView (I like this more). What should I do first in Xcode after installing pods?
Here is what I get:
Sometime Xcode can not see your pod after you install it in Swift. : (
You can fix issue by press Cmd+B for Build Project after you install Pod.
You forgot to import your library above your ViewController, so Xcode doesn't understand CalendarView
let import it:
import CalendarView
then build project to notify Xcode understand that you have just imported it :).
then initialize CalendarView inside your ViewController with it's frame, like so:
let calendar = CalendarView(frame: CGRectMake(0, 0, CGRectGetWidth(view.frame), 320))
view.addSubview(calendar)
if you want to use #IBOutlet weak var calendar: CalendarView!
You need to drag a UIView to your storyboard, then set it's class is CalendarView, then reference it to your IBOutlet. Hope this help you.
I manage to solve this on my own. I'll post an answer in case somebody else sucks here.
In my case, CalendarView.bundle was not present in .../Build/Products/Debug-iphonesimulator/CalendarView/
So I cp -r from /Library/Developer/Xcode/DerivedData/yourapp/Build/Products/Debug-iphonesimulator/CalendarView/CalendarView/CalendarView.bundle
This works.
I'm trying to learn ReactiveUI for a Xamarin.iOS project and I'm stuck on what should be a simple task. I am unable to bind a button click to a ReactiveCommand in the same way I can in my companion Xamarin.Android project. Here is the Android code that works fine:
this.BindCommand (ViewModel, x => x.ClickMe, view => view._button);
Here is the same pattern used in iOS:
this.BindCommand (ViewModel, x => x.ClickMe, view => view.GetForecastButton);
However, in iOS I get the following warning:
"Couldn't find a Command Binder for MonoTouch.UIKit.UIButton"
Does anyone know what I'm doing wrong? The astonishing thing is that I've looked up dozens of ReactiveUI iOS examples and I still haven't found one that has even a single button in the app. They all do something like show text from a bound property or show a UITableView from a collection in the ViewModel. I'm sure there is a more complete iOS example out there and if anyone knows of one please include in your answer. Many thanks.
You're doing everything correctly, but I believe you're being trolled by a Xamarin.iOS bug that affects ReactiveUI, where Type.GetType won't load assemblies. Paste this into your AppDelegate:
https://github.com/paulcbetts/starter-mobile/blob/master/Starter-iOS/AppDelegate.cs#L35
// NB: GrossHackAlertTiem™:
//
// Monotouch appears to not load assemblies when you request them
// via Type.GetType, unlike every other platform (even
// Xamarin.Android). So, we've got to manually do what RxUI and
// Akavache would normally do for us
var r = RxApp.MutableResolver;
(new ReactiveUI.Cocoa.Registrations()).Register((f,t) => r.Register(f, t));
(new ReactiveUI.Mobile.Registrations()).Register((f,t) => r.Register(f, t));