I did some more test, to check how to use topLevelObjects.
I replaced IBOutlets by simple properties.
It works well in Xcode, but crashes the same in Finder. But I do think that's the direction to look at.
Code Block final class KaraokeSongView: NSView { |
|
var rootView: NSView! |
|
var songTitleView: NSTextField! |
var currentTimeView: NSTextField! |
var songLengthView: NSTextField! |
var songPositionView: NSProgressIndicator! |
var playPauseButton: NSButton! |
var dragDestination: KaraokeSongDragDestinationView! |
var unpackProgress: NSProgressIndicator! |
var showInFinder: NSButton! |
|
var songDisplayView: NSImageView! |
var songVideoView: AVPlayerView! |
var volumeSlider: NSSlider! |
var songUrl: URL! |
var player = AVAudioPlayer() |
var avPlayer = AVPlayer() |
let formatter = DateComponentsFormatter() |
var currentCdgPacket = 1.0 |
var timer: Timer! |
var myArray : NSArray? |
|
required init?(coder: NSCoder) { |
|
super.init(coder: coder) |
let myName = type(of: self).className().components(separatedBy: ".").last! |
|
if let nib = NSNib(nibNamed: myName, bundle: Bundle(for: type(of: self))) { |
|
nib.instantiate(withOwner: self, topLevelObjects: &myArray) // nil) |
print("myArray count", myArray?.count) |
print("myArray[0]", myArray![0]) |
print("myArray[1]", myArray![1]) |
|
if let topView = myArray![0] as? NSView { |
print("topView 0", topView, topView.frame) |
for newView in topView.subviews { |
self.addSubview(newView) |
print("newView", type(of: newView), newView.frame) |
} |
} else if let topView = myArray![1] as? NSView { |
print("topView 1", topView, topView.frame) |
for newView in topView.subviews { |
self.addSubview(newView) |
print("newView", type(of: newView), newView.frame) |
} |
} |
|
// setup() |
|
} else { |
print("init couldn't load nib") |
} |
} |
myArray contains 2 objects: NSApplication and the top NSView
But in any order, hence the need to test [0] and [1].
Here the output, showing we get all the objects. And some errors at the beginning.
We should now need to connect to properties in the class.
2021-03-14 17:09:02.287271+0100 BugCode[50871:3973074] CDN - client insert callback function client = 0 type = 17 function = 0x7fff322a4246 local_olny = false
2021-03-14 17:09:02.287323+0100 BugCode[50871:3973074] CDN - client setup_remote_port
2021-03-14 17:09:02.287352+0100 BugCode[50871:3973074] CDN - Bootstrap Port: 1799
2021-03-14 17:09:02.287502+0100 BugCode[50871:3973074] CDN - Remote Port: 41999 (com.apple.CoreDisplay.Notification)
2021-03-14 17:09:02.287545+0100 BugCode[50871:3973074] CDN - client setup_local_port
2021-03-14 17:09:02.287567+0100 BugCode[50871:3973074] CDN - Local Port: 24579
2021-03-14 17:09:02.292836+0100 BugCode[50871:3973128] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x60000023f9c0> F8BB1C28-BAE8-11D6-9C31-00039315CD46
myArray count Optional(2)
myArray[0] <NSView: 0x100625a90>
myArray[1] <NSApplication: 0x6000035000b0>
topView 0 <NSView: 0x100625a90> (0.0, 0.0, 490.0, 340.0)
newView NSSlider (448.0, 27.0, 24.0, 255.0)
newView AVPlayerView (0.0, 0.0, 432.0, 280.0)
newView NSImageView (0.0, 0.0, 432.0, 280.0)
newView NSTextField (431.0, 292.0, 41.0, 16.0)
newView NSTextField (18.0, 316.0, 416.0, 16.0)
newView NSProgressIndicator (53.0, 289.0, 372.0, 20.0)
newView NSButton (440.0, 0.0, 40.0, 25.0)
newView NSBox (5.0, 286.0, 465.0, 5.0)
newView NSTextField (6.0, 291.0, 41.0, 16.0)
newView KaraokeSongDragDestinationView (0.0, 0.0, 490.0, 340.0)
newView NSButton (438.0, 306.0, 49.0, 32.0)
myArray count Optional(2)
myArray[0] <NSApplication: 0x6000035000b0>
myArray[1] <NSView: 0x10062b660>
topView 1 <NSView: 0x10062b660> (0.0, 0.0, 490.0, 340.0)
newView NSSlider (448.0, 27.0, 24.0, 255.0)
newView AVPlayerView (0.0, 0.0, 432.0, 280.0)
newView NSImageView (0.0, 0.0, 432.0, 280.0)
newView NSTextField (431.0, 292.0, 41.0, 16.0)
newView NSTextField (18.0, 316.0, 416.0, 16.0)
newView NSProgressIndicator (53.0, 289.0, 372.0, 20.0)
newView NSButton (440.0, 0.0, 40.0, 25.0)
newView NSBox (5.0, 286.0, 465.0, 5.0)
newView NSTextField (6.0, 291.0, 41.0, 16.0)
newView KaraokeSongDragDestinationView (0.0, 0.0, 490.0, 340.0)
newView NSButton (438.0, 306.0, 49.0, 32.0)
2021-03-14 17:09:02.334430+0100 BugCode[50871:3973128] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2021-03-14 17:09:02.371983+0100 BugCode[50871:3973074] Metal API Validation Enabled