Post

Replies

Boosts

Views

Activity

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
Window in all spaces
macOS, Swift, storyboards How can I make the window active in all spaces? I could find how to do that with storyboard: Select the window > Attributes > Spaces > Can join all spaces. How can I do the same with code (activate and de-activate)
1
0
922
May ’22
Swift Json with hyphens
(Swift, macOS, storyboards) //I have a JSON in a URL. Simplified it is something like this: {     "id": 1,     "name": "Leanne Graham",     "with-hyphen": 123 } //Outside the class ViewController: struct User: Codable {     let id: Int     let name: String     let with: Int } //In the class ViewController:     @IBAction func getJson(_ sender: NSButton) {         let url = URL(string: "https://example.com")!         URLSession.shared.dataTask(with: url) { data, _, _ in             if let data = data {                 let result = try? JSONDecoder().decode(User.self, from: data)                 //let result2 = result!.name //it works                 //let result3 = result!.with-hyphen //it does not work                 //print (result3)             }         }.resume()     } I can safe in a let the regular "id" and "name" but I do not know how to deal with the keys with hyphens, in the example: "with-hyphen"
1
1
1.8k
Sep ’21
Day of the week. From String to int
Is it possible to convert a var with the day of the week to a number? (and the other way around) let diaSetmana = "Monday" let diaSetmana2 = 2 I know how to convert from date(): let date = Date() let calendar = Calendar.current let dateFormatter = DateFormatter() dateFormatter.dateFormat = "EEEE" let dayString = dateFormatter.string(from: date) I am asking for converting not from date() but from a var that I have a random day of the week
1
0
797
Mar ’22
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
Make a link in macOS
How to make a link when I click to a button in macOS? This works well in iOS. How to do the same with macOS:     @IBAction func button1(_ sender: UIButton) {         if let url = URL(string: "some link") {             UIApplication.shared.open(url)         }     }
2
0
813
Aug ’22
Presentation single with code
(swift, macOS, storyboards) I open a window with code. Every time the user clicks the button the same window opens again and again. How to avoid that? This opens well the window, but multiple times:     @IBAction func obrirAmbCodi(_ sender: NSButton) {         let storyboard:NSStoryboard = NSStoryboard(name: "Main", bundle: nil)         guard let controller:NSWindowController = storyboard.instantiateController(withIdentifier: "finestra3") as? NSWindowController else { return }             controller.showWindow(self)     } If I open the window with a segue (storyboard control drag) I can accomplish that by selecting the window controller > Attributes > Presentation > Single. But it seems that it does not work if I open the window with code
2
0
698
Aug ’21
Animate a macOS window
(swift, macOS, storyboards) I can animate a window just adding animate: true to a regular way to control a window. Is there any way to control the animation, especially the time the animation will take? self.view.window?.setFrame(NSRect(x:0, y:0, width:300, height:300), display: true, animate: true)
2
0
1.1k
Aug ’21
Completion with JSON
(Swift, macOS, Storyboards) I can read a JSON from an URL. I would like to know when I can access the information. To be able to go from one function after the other. It seems that "completion" does not work with JSON? or perhaps I am doing something wrong? I give a simplified example: I try to get the JSON information in func first() and then do something with that information in func second()     var result2 = "empty"     func first(completion: ()->()) {         let url = URL(string: "https://jsonplaceholder.typicode.com/users")!         URLSession.shared.dataTask(with: url) { data, _, _ in             if let data = data {                 let result = try? JSONDecoder().decode([User].self, from: data)                 self.result2 = result![0].name             }         }.resume()         completion()     }     func second() {         //do something after first()         print (result2)     }     @IBAction func button1(_ sender: NSButton) {         first {           second()         }     }
2
0
927
Sep ’21
Open a View from the menu
(Swift, macOS, storyboards) How to open a view (not a window) by clicking a menu item? Let's suppose I have one window and two views: I try to open with Menu item: "open view 1" and item: "open view 2": (Here I asked the same question. Claude 31 solved very well with a button in one of the views. Here I am asking the same but with a button in the menu or menu item: https://developer.apple.com/forums/thread/690644 ) (Be aware that I am a beginner and I try to learn. Please explain in a simple way if possible)
2
0
1.8k
Sep ’21
Submit an macOS app and Xcode version
I have created a small app for macOS. I looked for information about how to submit it to the app store and read: "Build your apps using Xcode 13.1 or later…" https://developer.apple.com/macos/submit/ I have an old iMac Late 2013. Unfortunately, the last version I can install is Catalina 10.15.7, and the last Xcode I can install is version 12.4. Does it mean that I cannot publish my app? Is there any way I can submit it? Is buying a new mac the only solution? My iMac works well, and it is not easy for me to buy a new one. I would appreciate any recommendation Thank you
2
0
1.4k
Jul ’22
Remove the scroll in WebKit View
macOS, SwiftIs it possible to remove the scroll in WebKit View? (or make it not visible)I have a WebKit View from library and I have made the connection to the ViewController.swift:@IBOutlet weak var webView1: WKWebView!
Topic: UI Frameworks SubTopic: AppKit Tags:
6
0
6.9k
Sep ’21
How to stop an animation
(swift, storyboards, macOS) Can I stop or pause an animation? (I could find how to remove it: view1.layer?.removeAllAnimations() Here is the official documentation but I do not understand: https://developer.apple.com/documentation/uikit/uiviewanimating/1649843-pauseanimation)     @IBAction func fadeOut(_ sender: NSButton) {         NSAnimationContext.runAnimationGroup({ (context) in             context.duration = 5.0             view1.animator().alphaValue = 0         })     }
3
0
2.1k
Aug ’21