Post

Replies

Boosts

Views

Activity

Reply to very weird swiftui button behavior
the ContentView.swift alone is over three hundred lines, so that seemed a bit much to paste in, which is why I provided the link to the full project on github. When I said "underneath body" I meant how, in ContentView.swift, you have the basic structure of the file: import SwiftUI struct ContentView: View { var body: some View { <most code goes here> } } #Preview { ContentView() } the current issue i'm seeing happens when I have @State var buttonBlank: Bool = true after the ContentView: View line but before the var body: some View line. If I put it after var body: some View, then I don't get the weird 4 cycle-blank other buttons weirdness, but buttonBlank never updates. sorry if that bit was less than clear.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to How to increment an integer in a ForEach loop
okay, so the idea here is an "SOS" game (current project at https://github.com/johncwelch/SOS-Swift) basically, it's an over complicated version of tic-tac-toe, where each player attempts to spell SOS by clicking on the buttons. the buttons have three options: Blank (starting default) "S" "O" The buttons can also be enabled or disabled depending on a few things: if they've already been used, then they're not clickable if they're blank, but another button is being used by a player, they have to be enabled when that other button is blank, but disabled when the other button is "S" or "O" so that only one button can be used in a move. So on completion of a move, the following has to happen: If "S", are any of the buttons next to me "O"? If so, is the button in a line with that "O" an "S". If so, SOS, set the button color of all three to match the player color, (red or blue), disable myself, add a point to the player who made SOS, and change the current player to the other player. If not, just disable the button and change the current player to the other player. if "O", are the buttons on opposite sides of me both "S"? If so, SOS, set the button color of all three to match the player color, (red or blue), disable myself, add a point to the player who made SOS, and change the current player to the other player. If not, just disable the button and change the current player to the other player. So i need to be able to both read state of other buttons on the playing field and modify the state of other buttons based on what happens in a click on a current button. There's also a "new game" option, which blows up any current game (if in the middle), sets scores to 0 and sets all buttons to blank + enabled. Tracking button state is kind of critical here, both for the current title of the button and its enabled/disabled state.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to Capabilities for Location Services
documentation radar: FB10364979 On how to do this, I meant with location services. So I managed to muddle through some of it (y'all really need to look at how MS does their dev docs, the sample code for things here is really skimpy) What I have so far: in my "main" file (not the contentview file): class locationDelegate: NSObject, CLLocationManagerDelegate { func theLocationAuthStatus(_manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { print("changed auth status: \(status.rawValue)") switch status.rawValue { case 0: print("Not Determined") case 1: print("Restricted") case 2: print("Denied") case 3: print("Authorized Always") case 4: print("Authorized when in use") default: print("None of the above") } } } In my ContentView file: @State var myLocationManager = CLLocationManager() <lots of swiftui UI stuff> .onAppear {     let myDelegate = locationDelegate()     myLocationManager.requestWhenInUseAuthorization()     myLocationManager.startUpdatingLocation()     myLocationManager.delegate = myDelegate     myLocationManager.delegate     print(myLocationManager.authorizationStatus.rawValue)     let myLocationManagerAuthStatus = myLocationManager.authorizationStatus.rawValue     if myLocationManagerAuthStatus == 3 || myLocationManagerAuthStatus == 4 { //get BSSID     print("we're authorized")     currentWAPMAC = getBSSID()     }     //set up the SSID value     currentSSID = getSSID()     //get the Wifi Channel. if it's a zero,     //channel is actually nil     currentChannel = getCWChannelNumber()     //set up the RSSI     signalStrength = getRSSI()     //BRING THA NOIZE     signalNoise = getNoise()     //get the SNR as a formatted string via NumberFormatter     signalToNoise = getSNR(theSig: signalStrength, theNoise: signalNoise)     //get transmit rate     dataRate = getTransmitRate()     //get current time     self.theCurrentTime = getCurrentTime()     //stop the timer     self.stopTimer()     } create the interface object: func getWifiInterface() -> CWInterface { let theWirelessClient = CWWiFiClient.shared() let theWirelessInterface = theWirelessClient.interface() return theWirelessInterface! } //moved this from contentview to here. Probably a better place for all this var theWifiInterface: CWInterface = getWifiInterface() the getBSSID() function: func getBSSID() -> String { if let theBSSID = theWifiInterface.bssid() { return theBSSID } else { let theBSSID = "no BSSID" return theBSSID } } So on run, print(myLocationManager.authorizationStatus.rawValue) prints a 3, so cool, we're auth'd and the dialog has been appearing nice and consistent-like and the  if myLocationManagerAuthStatus == 3 || myLocationManagerAuthStatus == 4 { //get BSSID     print("we're authorized")     currentWAPMAC = getBSSID() } prints "we're authorized" as expected, but no BSSID returned. Everything else, the SSID, the channel, the Signal/Noise strengths, the Data Rate, that I get fine, but I can't get the BSSID. I know I'm missing something simple, but i'm completely puzzled as to what. Thanks!
Jun ’22
Reply to How to disable window resizing in swiftui on macOS?
Thanks! Took me a hot sec to figure out this wasn't in the contentview file, but once I stopped being dumb, I got this: struct WiFi_AnalyzerApp: App { //implement AppDelegate custom class so we quit on closing window @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate     var body: some Scene {   WindowGroup {   ContentView() //set up the min/max size   .frame(minWidth: 785, maxWidth: 785, minHeight: 212, maxHeight: 212)   }     //lock it down so you can't change it   .windowResizability(.contentSize)     } } and it's working exactly as I wanted. Thanks!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22
Reply to AppleScript requires elevated privileges after upgrade to MacOS 12 (and now 12.1)
I haven't seen that myself, even using the finder, so it may just be that user. However, you don't need the finder for that anyway. Display Dialog is part of the standard additions so: osascript -e 'display dialog "Hello, World!"' works without involving the Finder. you may also want to check various Library/ScriptingAdditions/ folders to see if there's maybe not some older third party thing causing you issues. (Adobe has caused this issue a lot for people over the years)
Topic: App & System Services SubTopic: Core OS Tags:
Feb ’22