I have developed an app using SceneKit since Swift came out. Now SwiftUI is out and uses structs rather than classes. SceneKit is a cascade of classes. As a newbie, I am concerned that my code might be obsolete through depreciations soon after publication and I'd rather get ahead of the issues now. So, is SceneKit long-term viable? My first attempts at converting my custom classes to structs seems impossible without Apple leading the way. If I understand correctly, I can make a struct whose only member is an instance of a class, but the benefits of the struct, e.g., minimal memory, processing time, etc., are lost.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I launch the following runSavePanel() from, e.g.,
@IBAction func JSONall(_ sender: NSButton) {
if !nsPanelActivatedThisSessionForSandbox {
nsPanelActivatedThisSessionForSandbox = true
runSavePanel() }
...
}
where var nsPanelActivatedThisSessionForSandbox = false
is declared as a global in the AppDelegate.swift file and is intended to prevent repeated user prompting as the program creates many files but needs sandbox acknowledgment at least once.
The problem behavior is that upon clicking the OK button, the app merrily creates the files in the chosen directory but the modal window stays open until the app is done creating files (around ten minutes). Here is my runSavePanel() and its (empty) delegate:
func runSavePanel() {
let defaults = UserDefaults.standard
let savePanel = NSSavePanel()
savePanel.canCreateDirectories = true
savePanel.canSelectHiddenExtension = false
savePanel.showsHiddenFiles = false
// savePanel.allowedFileTypes = ["JSON", "csv"] // deprecated
savePanel.directoryURL = defaults.url(forKey: "fileDirectoryPref")
let delegate = OpenSavePanelDelegate() // cannot consolidate with next line
savePanel.delegate = delegate
let result = savePanel.runModal()
if result == NSApplication.ModalResponse.OK {
if savePanel.url != nil {
do {
try savePanel.delegate!.panel!(savePanel, validate: savePanel.url!)
defaults.set(savePanel.url, forKey: "fileDirectoryPref")
// defaults.set(savePanel.url, forKey: "NSNavLastRootDirectory") // does not write
} catch {
print("\(result) ViewController Structures.swift:739 runSavePanel()")
}
}
}
}
class OpenSavePanelDelegate: NSObject, NSOpenSavePanelDelegate {
func panel(_ sender: Any, validate url: URL) throws {
/* In Swift, this method returns Void and is marked with the throws keyword to indicate that it throws an error in cases of failure.
You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.
*/
// throw CustomError.InvalidSelection
}
}
// enum CustomError: LocalizedError {
// case InvalidSelection
//
// var errorDescription: String? {
// get {
// return "\(CustomError.InvalidSelection)"
// }
// }
// }
Idk how to stop the double spacing when pasting my code. Sorry.
The delegate is a requirement but I don't know how to configure it. The app doesn't generate errors... or at least it allows the desired output.
Is the delegate supposed to terminate the modal window somehow?
My SceneView hides part of my NSStackView's TextFields. I don't see anything in the inspector for the z dimension. How can I ensure the StackView is on top, i.e., wholly visible?
I don't want to shove views around to "fit them in". They must overlap.
Indeed, I may wish to have all TextFields, etc. overlay the SceneView in the future, but that's a different subject.
I know this would be easy in SwiftUI, but...
As stated in the title, I want to hide or show a StackView when a menu item is selected, which in turn changes a global variable.
How do I access the identity or handle of the StackView?
I have modified Apple's Tutorial "CPU-GPU-Synchronization.xcodeproj" to suit my needs but cannot see how to launch it, e.g., as a sheet, from a Button inside a SwiftUI App.
I found this:
"developer.apple.com/forums/thread/119112"
which establishes the Coordinater wrapper, device and CommandQueue, etc., but how do I "replace?" those already established in ObjC code? For example, ObjC does not recognize SwiftUI struct's and I can't @objc preface a SwiftUI struct as I can a SwiftUI class(ref. the above thread).
Alternatively, is this the best venue to ask Apple to update/integrate their tutorials?
Thanks.