Post

Replies

Boosts

Views

Activity

Reply to How to turn on wifi or bluetooth using a button in my app
I doubt this is possible. Imagine some nefarious app gets installed that does something nasty like turning off your Wi-Fi, Bluetooth, Mobile Data etc. Would you want that? Even the Shortcuts app doesn't let you do that. You can't even force iOS to do something benign like switching to Dark Mode etc. because why should an app have control over such a system setting that affects lots of other things?
Apr ’24
Reply to function with automatically increasing percentage (watchOS)
I think there's a bit too much code here for us to figure out what's going on. Can you provide a minimum reproducible example? How about explaining exactly where things are going wrong? Also, "Already tried to get help from AI, but did not solve the problem." Don't resort to "AI" to fix your problems. It doesn't work. Large Language Models work on patterns, and aren't really going to figure out where you're going wrong with this code.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’24
Reply to How to Persist App Data (UserDefaults)?
I wouldn't over-complicate it just yet. Add a print statement every time you write to or read from the defaults. It might be that you're wiping out a value accidentally. I was getting a similar issue because I had spelled a key wrongly. I was writing "events" and reading "evetns" in one place. Changed to using constants (let kEvents: String = "events" etc.), and everything is fine; no opportunity for typos. I also created set and get functions for the UserDefaults: func settingsSet(_ value: Any, forKey key: String) { UserDefaults(suiteName: kAppGroup)?.set(value, forKey: key) UserDefaults(suiteName: kAppGroup)?.synchronize() } func settingsGetBool(forKey key: String, withFallback fallback: Bool) -> Bool { guard let value = UserDefaults(suiteName: kAppGroup)?.object(forKey: key) else { return fallback } return value as? Bool ?? fallback } // ... repeat for Int, String, Date... // Then, each individual setting has functions like this: func settingsSetUseImages(_ value: Bool) { settingsSet(value as Bool, forKey: kSettingsUseImages) } func settingsGetUseImages() -> Bool { return settingsGetBool(forKey: kSettingsUseImages, withFallback: true) } // Usage: settingsSetUseImages(true) // Set to true let useImages = settingsGetUseImages() // Get current value, and if not set, return `fallback` of true You can add a print statement to the defaultsSet function to write out what value is being set for which key. By abstracting that out you can also replace the means of storing settings values later on without having to change any of the instances of where you're actually updating/reading those values. Hope this helps. Might be overkill for your issue, but it helped me :)
Topic: App & System Services SubTopic: General Tags:
Apr ’24
Reply to Cannot infer contextual base in reference to member 'background'
You've put the .background modifier at the very beginning of your view. Do you know how object-oriented programming works? An object has a bunch of properties, and you access using the dot notation, so: MyObject .background(Color.red) What you've done is tried to apply a modifier to... nothing. Where do you want the gradient? Behind the TabView? Put the .background modifier on the TabView, i.e.: TabView { WelcomePage() FeaturesPage() } .tabViewStyle(.page) .background(Gradient(colors: gradientColors))
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’24