0

I'm creating an app for Mac OSX, (I don't know anything about SwiftUI/Cocoa) this app needs to be hidden when the user presses one button and at a certain time the app should pop-up again.

It's a reminder app:

@IBAction func hidMe(_ sender: NSButton) {
        window.close() //I know this will remove the window, but I didn't find another way...
    }

//I created this function that was supposed to bring the window to front, but I have no idea how to call it.
func reopen() {
        let now = Date()
        
        let components = Calendar.current.dateComponents([.month, .day, .hour, .minute], from: now)
        
        if ((components.hour == 9) && (components.minute == 16)) {
            window?.makeKeyAndOrderFront(self)
        }
lorem ipsum
  • 21,175
  • 5
  • 24
  • 48
DSouza
  • 13
  • 5
  • This doesn't have anything to do with SwiftUI. `IBAction`, `NSButton` are all `UIKit`/`AppKit` – lorem ipsum May 07 '21 at 14:51
  • awesome, thanks lorem ipsum! – DSouza May 07 '21 at 19:20
  • Is the question about closing the window, hiding the app or using a timer? – Willeke May 07 '21 at 20:18
  • Hiding the app and using a timer to unhide it – DSouza May 08 '21 at 12:47
  • See [hide(_:)](https://developer.apple.com/documentation/appkit/nsapplication/1428733-hide) and [unhide(_:)](https://developer.apple.com/documentation/appkit/nsapplication/1428761-unhide). – Willeke May 08 '21 at 23:31
  • Does this answer your question? [How can I use Timer (formerly NSTimer) in Swift?](https://stackoverflow.com/questions/24007518/how-can-i-use-timer-formerly-nstimer-in-swift) – Willeke May 08 '21 at 23:32

0 Answers0