Post

Replies

Boosts

Views

Activity

Reply to NSOpenPanel not closing after OK button
how to stop the double spacing when pasting my code This is easy: use the menu Paste and Match Style. You do not show much code, so hard to be sure. But you should replace         let delegate = OpenSavePanelDelegate()      //  cannot consolidate with next line         savePanel.delegate = delegate by         // -->>> REMOVE THIS LINE: let delegate = OpenSavePanelDelegate()      //  cannot consolidate with next line         savePanel.delegate = self // The class in which this code is And declare that your class (a viewController probably) conforms to NSOpenSavePanelDelegate
Topic: UI Frameworks SubTopic: AppKit Tags:
Sep ’21
Reply to NSOpenPanel not closing after OK button
Could you show the complete code of the class ? Thanks to Paste to avoid extra blank lines. To save, code structure is as follows: let savePanel = NSSavePanel() savePanel.title ="Create file" savePanel.prompt = "Create" savePanel.allowedFileTypes = ["xxxx"] // what you need let fileManager = FileManager.default savePanel.begin() { (result) -> Void in if result == NSApplication.ModalResponse.OK {                 let saveURL = savePanel.url! self.saveToFile(data: data, on: saveURL) // data defined elsewhere } } What I do when I need to access a new directory, to manage sandboxing : call NSOpen to select the directory where to save save bookmarks then call savePanel inside the completionHandler of the openPanel. I admit, using sandbox may be nightmarish.
Topic: UI Frameworks SubTopic: AppKit Tags:
Sep ’21
Reply to NSOpenPanel not closing after OK button
Why do you need to set a delegate ? There seems to be a limited number of delegate functions. Which one do you use ? func panel(Any, userEnteredFilename: String, confirmed: Bool) -> String? Tells the delegate that the user confirmed a filename choice by clicking Save in a Save panel. func panelSelectionDidChange(Any?) Tells the delegate that the user changed the selection in the specified Save panel. func panel(Any, didChangeToDirectoryURL: URL?) Tells the delegate that the user changed the selected directory to the directory located at the specified URL. func panel(Any, willExpand: Bool) Tells the delegate that the Save panel is about to expand or collapse because the user clicked the disclosure triangle that displays or hides the file browser. func panel(Any, shouldEnable: URL) -> Bool Asks the delegate whether the specified URL should be enabled in the Open panel. func panel(Any, validate: URL) Asks the delegate to validate the URL for a file that the user selected.
Topic: UI Frameworks SubTopic: AppKit Tags:
Sep ’21
Reply to Why isn't the date assigned to the object property?
You have to create it first: newDate = NewDate() here:     override func viewDidLoad() {         super.viewDidLoad()         let date = pickerOutlet.date         print(date) // Prints: 2021-09-03 03:56:17 +0000 newDate = NewDate() // <<-- Add this         newDate?.date = pickerOutlet.date         print(newDate?.date) // Prints: nil     }
Topic: UI Frameworks SubTopic: UIKit Tags:
Sep ’21
Reply to Fetch Core Data Issue
I still have trouble getting the save to work. What problem exactly ? No save at all ? partial save ? What do you get from:     print("These are my saved objects: \(saveFav)") Could you show more of convenience init ? It seems you get only one value.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21