Post

Replies

Boosts

Views

Activity

Do something at a specific time
I want my program to do something at a specific time. This is what I have tried: func rellotge() { countdownRellotge = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(actualitzaRellotge), userInfo: nil, repeats: true) } @objc func actualitzaRellotge() { let date = Date() let calendar = Calendar.current hour = calendar.component(.hour, from: date) minutes = calendar.component(.minute, from: date) seconds = calendar.component(.second, from: date) //print (minutes, ":", seconds) if (minutes == 40 && seconds == 0){ print ("do something") } } This does not work if the computer goes to sleep. Even before that, it becomes buggy. (When I print the seconds, it seems that sometimes it skips some seconds) How can I reliably make my program do something at a specific minute-second?
1
0
581
Apr ’22
macOS Menu Bar
Xcode 16.2 Swift 6 macOS Sequoia 15.1 SwiftUI I am a beginner. If I understand we can add buttons to the default Menu Bar but not delete them. Am I right? If you do not need most of the buttons, how do you solve that? I can add a button: import SwiftUI @main struct NouMenuProvesApp: App { var body: some Scene { WindowGroup { ContentView() } .commands { CommandMenu("Custom") { Button("Custom Action") { print("Custom Action performed") } } } } } Can I delete a Menu Button or create a new simpler Menu Bar?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
1
0
299
Jan ’25
NSView not transparent in a transparent window
(Swift, macOS, storyboards.) I have a window that is semitransparent and a NSView that I want to be not transparent or with a different transparent degree. With my code, if I make the window transparent the NSView is also transparent. func finestra() { self.view.window?.alphaValue = 0.7 } func nsView1() { nsViewOutlet.wantsLayer = true nsViewOutlet.layer?.backgroundColor = NSColor.white.cgColor nsViewOutlet.alphaValue = 1 }
0
0
600
Mar ’22