I am working on integrating some C-sharp code into a Swift application by using Mono. This is working fine but I want to make that integration optional. So, I changed the Mono.framework linking in Xcode to be optional and confirmed that's the result in the linker command line.
Now, my question is how can I check if the Mono.framework is actually available for use? I have only seen examples that check for Objective-C classes but none that deals with standard C function availability.
As far I can tell, I don't see anything special in the Mono headers that would help me and attempting to check if a function is available directly, such as mono_jit_init doesn't work because it is just checking the stub address.
Post
Replies
Boosts
Views
Activity
I have seen a few reports of crashes like the following:
0 HSTracker 0x000000010b816eaf HSTracker.TrackersPreferences.viewDidLoad() -> () (TrackersPreferences.swift:0)
1 HSTracker 0x000000010b816ef8 @objc HSTracker.TrackersPreferences.viewDidLoad() -> () (<compiler-generated>:0)
2 AppKit 0x00007ff814505a92 -[NSViewController _sendViewDidLoad] + 86
3 AppKit 0x00007ff8144eded2 -[NSViewController _loadViewIfRequired] + 384
4 AppKit 0x00007ff8144edd16 -[NSViewController view] + 22
5 HSTracker 0x000000010b99e2a3 Preferences.PreferencesTabViewController.(setWindowFrame in _1B0415CEB51F45D735E92B4C0504C08B)(for: __C.NSViewController, animated: Swift.Bool) -> () (PreferencesTabViewController.swift:193)
6 HSTracker 0x000000010b99e7e3 closure #1 (__C.NSAnimationContext) -> () in Preferences.PreferencesTabViewController.transition(from: __C.NSViewController, to: __C.NSViewController, options: __C.NSViewControllerTransitionOptions, completionHandler: () -> ()?) -> () (PreferencesTabViewController.swift:169)
7 HSTracker 0x000000010b99f089 partial apply forwarder for closure #1 (__C.NSAnimationContext) -> () in Preferences.PreferencesTabViewController.transition(from: __C.NSViewController, to: __C.NSViewController, options: __C.NSViewControllerTransitionOptions, completionHandler: () -> ()?) -> () (<compiler-generated>:0)
8 HSTracker 0x000000010b99f0c1 partial apply forwarder for reabstraction thunk helper from @callee_guaranteed (@guaranteed __C.NSAnimationContext) -> () to @escaping @callee_guaranteed (@guaranteed __C.NSAnimationContext) -> () (<compiler-generated>:0)
9 HSTracker 0x000000010b99e8e8 reabstraction thunk helper from @escaping @callee_guaranteed (@guaranteed __C.NSAnimationContext) -> () to @callee_unowned @convention(block) (@unowned __C.NSAnimationContext) -> () (<compiler-generated>:0)
10 AppKit 0x00007ff8144b01ab +[NSAnimationContext runAnimationGroup:] + 54
11 HSTracker 0x000000010b99dfed Preferences.PreferencesTabViewController.(animateTabTransition in _1B0415CEB51F45D735E92B4C0504C08B)(index: Swift.Int, animated: Swift.Bool) -> () (PreferencesTabViewController.swift:165)
12 HSTracker 0x000000010b99da1f Preferences.PreferencesTabViewController.activateTab(index: Swift.Int, animated: Swift.Bool) -> () (PreferencesTabViewController.swift:85)
13 HSTracker 0x000000010b9a45c3 Preferences.ToolbarItemStyleViewController.(toolbarItemSelected in _7A80F77958D94D970CD625FA09110540)(__C.NSToolbarItem) -> () (ToolbarItemStyleViewController.swift:0)
14 HSTracker 0x000000010b9a461f @objc Preferences.ToolbarItemStyleViewController.(toolbarItemSelected in _7A80F77958D94D970CD625FA09110540)(__C.NSToolbarItem) -> () (<compiler-generated>:0)
15 AppKit 0x00007ff8147f302f -[NSToolbarButton sendAction:to:] + 106
16 AppKit 0x00007ff81479092e -[NSToolbarItemViewer mouseDown:] + 5172
17 AppKit 0x00007ff814692bc1 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 4858
18 AppKit 0x00007ff814606d7e -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2581
19 AppKit 0x00007ff81460614e -[NSWindow(NSEventRouting) sendEvent:] + 351
20 HSTracker 0x000000010b9a5429 @objc Preferences.UserInteractionPausableWindow.sendEvent(__C.NSEvent) -> () (Utilities.swift:92)
21 AppKit 0x00007ff814604524 -[NSApplication(NSEvent) sendEvent:] + 351
22 AppKit 0x00007ff8148bd18b -[NSApplication _handleEvent:] + 64
23 AppKit 0x00007ff814485d3e -[NSApplication run] + 622
24 AppKit 0x00007ff814459c97 NSApplicationMain + 816
25 HSTracker 0x000000010b762fe9 main (AppDelegate.swift:21)
26 ??? 0x000000011616152e 0x0 + 0
Decoding the crash location with xcrun atos -i always points to a line dereferencing an IBOutlet that is nil.
Is there an explanation for while would the outlet not be connected?
The preferences pane is shown here:
https://github.com/HearthSim/HSTracker/blob/master/HSTracker/AppDelegate.swift#L595
The above crash happens on the following line:
https://github.com/HearthSim/HSTracker/blob/master/HSTracker/UIs/Preferences/TrackersPreferences.swift#L44
Any help is appreciated.
I have a window with an NSView anchored to its top. This view needs to support user configurable scaling between 0.5 and 1.0 and stay anchored at the top left corner of its parent/window.
I tried to use scaleUnitSquare which does work but I didn't find a way to reset it and to get the view properly anchored at the top left corner.
I then tried to wrap the view with an NSScrollView and set its magnification as desired. This works well but the view is anchored to the bottom left no matter what I have tried.
Is there a good way to accomplish this?
This is similar to this post https://developer.apple.com/forums/thread/700770 on using objc_copyClassList to obtain the available classes. When iterating the list, I try casting the result to an instance of a protocol and that works fine:
protocol DynamicCounter {
init(controlledByPlayer: Bool, game: Game)
}
class BaseCounter: NSObject, DynamicCounter {
}
static func withAllClasses<R>(
_ body: (UnsafeBufferPointer<AnyClass>) throws -> R
) rethrows -> R {
var count: UInt32 = 0
let classListPtr = objc_copyClassList(&count)
defer {
free(UnsafeMutableRawPointer(classListPtr))
}
let classListBuffer = UnsafeBufferPointer(
start: classListPtr, count: Int(count)
)
return try body(classListBuffer)
}
static func initialize() {
let monoClasses = withAllClasses { $0.compactMap { $0 as? DynamicCounter.Type } }
for cl in monoClasses {
cl.initialize()
}
}
The above code works fine if I use DynamicCounter.Type on the cast but crashes if try casting to BaseCounter.Type instead.
Is there a way to avoid the weird and non Swift classes?
I am trying to understand why I am seeing crash reports for my code that creates a view from a NIB like the code below. The crash occurs when referencing contentView which should have been bound when the NIB was loaded.
Am I missing something here other than checking the result of the loadNibNamed function call?
class MyView: NSView {
@IBOutlet var contentView: NSView!
init() {
super.init(frame: NSRect(x: 0, y: 0, width: 84.0, height: 49.0))
commonInit()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func commonInit() {
Bundle.main.loadNibNamed("MyView", owner: self, topLevelObjects: nil)
translatesAutoresizingMaskIntoConstraints = false
contentView.translatesAutoresizingMaskIntoConstraints = false
addSubview(contentView)
contentView.frame = self.bounds
}