Questions tagged [userdefaults]

507 questions
3
votes
3 answers

UserDefault always return nil

UserDefaults are not working in my App. Please find the below code under AppDelegate file. let sharingData = UserDefaults.init(suiteName: "group.macuser79.xxx"); sharingData?.set("vincenzo", forKey:"username"); sharingData?.synchronize(); In the…
macuser
  • 567
  • 2
  • 6
  • 16
3
votes
2 answers

Swift 3 / iOS 10 / TodayExtension - UserDefaults always returns nil

This is my first Question on this site. I have a problem that I cannot fix. I'm working on an easy note application with today extension. I have had no problem in Swift 2.2 and iOS 9. Problem just appears in Swift 2.3 and Swift 3, on iOS 10. The…
Darkkrye
  • 51
  • 5
2
votes
1 answer

How to detect if button was pressed after app restart in swift?

I am trying to determine if user selected the "reset" button after the app restarts. With this code, it will go back to the root controller when the app is open or in the background. Once I terminate the app and re-open, the app is still as if the…
2
votes
3 answers

Swift Swiftui - Saving Color to UserDefaults and use it from @AppStorage

In my App for MacOS and iOS I use colors created from here: https://uiwjs.github.io/ui-color/ and then f.e. Works fine. Color(red: 1.47, green: 1.9, blue: 2.3).opacity(1) However for some colors I want them saved in the userDefaults and read/write…
iPadawan
  • 898
  • 1
  • 12
  • 23
2
votes
2 answers

(SwiftUI) How to make text hidden when view loads and become visible once toggle is tapped

I'm trying to create a view with a toggle. the toggle changes ui preferences. when the toggle is changed it changes the Text below. as it stands the easiest way to do this is VStack { Toggle("toggle me", isOn: $isOn) …
zamanada
  • 158
  • 13
2
votes
1 answer

SwiftUI: Binding to @AppStorage

In the following example how can I change the value of activeSheet based on how SwiftUI updates aArrived and bArrived? struct ContentView: View { @AppStorage("didAArrive") var aArrived: Bool = false @AppStorage("didBArrive") var bArrived:…
Isaak
  • 1,107
  • 2
  • 11
  • 29
2
votes
1 answer

SwifUI : pass a stored value (via user defaults) to another view

I used user defaults to save the values from a form. I wish to pass one of those values ("nationality") to another view. I tried using the view model in order to do so, but I get an empty value in the text where I wish to pass this data. first here…
LEKYSMA
  • 141
  • 10
2
votes
1 answer

IntentHandler can’t read UserDefaults but Timeline can

I want to read UserDefaults when a user changes the configuration for a widget, so I created an app group and added the capabilty to my main app, the widget extension and the Intent extension. I can read and write fine between my app and the widget…
Kipnoedels
  • 1,118
  • 7
  • 22
2
votes
1 answer

How do I decode an object array and retrieve it from userdefaults?

I have an array with type [NotificationTriggers] that I would like to store in userdefaults. To do that, the data needs to be encoded and decoded. I have followed tutorials…
Joakim Sjöstedt
  • 824
  • 2
  • 9
  • 18
2
votes
2 answers

How can you remove whitespaces accidentally entered by a user when entering setting values (Userdefaults)

I'm using Swift5's UserDefaults to store text key pair preferences. What some users of my app have been doing is accidentally adding a space before or after the string which is then causing problems. Please can someone advise me on how I can…
2
votes
1 answer

How can I create a Swift Combine publisher from two publishers A and B where publisher B consumes the value from publisher A?

I want to create a Swift Combine publisher which achieves the following: The publisher should be triggered by changes in either Defaults (a UserDefaults Swift package) or changes in GRDB sqlite database values (using GRDBCombine). The updated…
Simen
  • 417
  • 6
  • 13
2
votes
1 answer

UserDefaults not being saved and update after first time in SwiftUI

I created a simple system to navigate on-screen according to the UserDefaults value, I have a key ”rootStatus” that key I placed inside the enum. I used @PropertyWrapper for storing the value of user default. Place UserDefaults Key inside the…
Ravindra_Bhati
  • 1,071
  • 13
  • 28
2
votes
2 answers

Best Practice to store local data in ios framework project

I am working on a custom framework which will be used by developers. I am saving some data locally inside my framework for that I am thinking to use UserDefaults but I want to know: Is it the best method to do so? If the app UserDefaults are…
Abhishek
  • 1,654
  • 2
  • 18
  • 31
2
votes
3 answers

User Defaults Swift

I have hint view (tooltip). And I want it display in my app 1 time per download app. When user downloading app this tooltip is showing and then dismiss. When user delete app and again downloading tooltip should work again. let options:…
2
votes
3 answers

SwiftUI: setting userdefaults specifically to struct properties

I want to set the variable "isfavorite" mapped to "id" as UserDefaults. I am able to save the whole of the struct encoded as JSON to UserDefaults. And then decode the UserDefaults JSON on init. There are two problems with this approach 1) I am…
Dar
  • 57
  • 1
  • 11