Questions tagged [userdefaults]

507 questions
6
votes
4 answers

How do I check if userDefault is empty?

I'm trying to deny access to a certain view controller if the userDefault is empty, but the code doesn't seem to work. To be a bit more clear, I'm saving a favorite-list to a userDefault. This is my code: if UserDefaults.standard.array(forKey:…
Joakim Sjöstedt
  • 824
  • 2
  • 9
  • 18
6
votes
0 answers

userDefaults reset / wiped after iOS 10.3 update

In my SpriteKit game I use UserDefaults to save high scores etc. Works fine, everything working smoothly. however - I just updated some devices to iOS 10.3 (release, not beta) and I noticed that previously saved data is wiped... new data is…
Adam
  • 373
  • 4
  • 13
5
votes
1 answer

Update SwiftUI View when Object in Userdefaults changes

I am Working on an App in XCode that Displays Locations saved on a JSON file from an URL. I have saved the users favorite Locations in the UserDefaults.standard.object(forKey: "heart") The heart button on the SpotDetailView saves the spot and also…
5
votes
1 answer

Retrieve only the keys & values which I stored in UserDefaults

I have created UserDefaults with suite, self.moviesWatchedUserDefaults = UserDefaults(suiteName: "com.apple.tv.2020") And storing the info in the plist like self.moviesWatchedUserDefaults.set(data, forKey: key). Now, while retrieving, I wanted to…
user2431170
  • 151
  • 2
  • 11
5
votes
7 answers

Going crazy with UserDefaults in Swift[UI]

Launching myself into Swift and SwiftUI, I find the process of migrating from UIKit quite hard. Presently stomped by UserDefaults, even after trying to make sense of the many tutorials I found on the web. Please tell me what I'm doing wrong here…
Esowes
  • 287
  • 2
  • 13
5
votes
3 answers

Access Flutter SharedPreferences in Swift

Is it possible to access SharedPreferences saved from Flutter accessed in Swift code of plugin? In Android we have FILE mode for SharedPreferences. Any similar feature in Swift 4?
sandy
  • 3,311
  • 4
  • 36
  • 47
5
votes
1 answer

How to save a default printer in UserDefaults in Swift?

This is the workflow of my app: User can select a default printer from app's settings page and will use this default printer to print every time directly without any print preview dialogue. We can select a printer using…
anas.p
  • 2,246
  • 19
  • 26
5
votes
1 answer

What is real meaning of suiteName in UserDefaults initializer?

I attempting to grasp some kind of unit tests, so we create mock user defaults. class MockUserDefaults: UserDefaults { var gameStyleChanged = 0 override func set(_ value: Int, forKey defaultName: String) { if defaultName == "something" { …
Ninja
  • 309
  • 7
  • 26
5
votes
2 answers

Difference between UserDefaults() and UserDefaults.standard

Is there a difference between UserDefaults() and UserDefaults.standard in Swift 3.0?
rolling_codes
  • 15,174
  • 22
  • 76
  • 112
4
votes
2 answers

Where to place the .register() method to set an initial/default value for UserDefaults?

I am currently struggling to figure out where to correctly place the .register() method to set an initial/default value for UserDefaults (on every launch of the app). Here is where I tried to initialize it in the "App" file that Xcode generated with…
Malburrito
  • 860
  • 7
  • 23
4
votes
3 answers

ios 14 widget: How to reload timeline after UserDefaults changed

I have a ios 14 widget that refresh every 5 minutes let timeline = Timeline(entries: entries, policy: .atEnd) The entries depends on the configuration on my MainApp. I use UserDefaults to share data between MainApp and…
Neo.Mxn0
  • 953
  • 2
  • 8
  • 25
4
votes
3 answers

How I can save picker data with UserDefaults in SwiftUI?

I'm trying to save the user choice from picker component in UserDefault in SwiftUI but in contrary of a simple toggle, I'am blocked. My View: import SwiftUI enum VibrationType: String, CaseIterable { case low = "Faible" case normal = "Normal" …
Guillaume
  • 1,500
  • 3
  • 24
  • 33
4
votes
2 answers

Why isn't UserDefaults.standard.set saving my array? After the application is removed from background the data is cleared

I'm currently working on a calendar within my application I'm writing using Swift. Although it works correctly in that data (event logs) can be entered and added to an array which will show up within a table view, once the application is closed down…
Lnskip
  • 73
  • 5
4
votes
2 answers

Saving time in UserDefaults

I'm working on a little game. When the user has a game going and shuts down the game, the app saves a timestamp so when he returns it can calculate, in seconds, for how long time he was away. My problem is, that when the app re-opens it crashes. I…
theloneswiftman
  • 188
  • 1
  • 4
  • 17
4
votes
1 answer

Storing UITextView String / Text Data

So I am trying to create a view that displays a large text view that's editable. In the storyboard it's edited to display the text "Take your notes here (Swipe Down to dismiss the keyboard): " as a placeholder. I'd like for it to remember when a…
KSigWyatt
  • 1,368
  • 1
  • 16
  • 33
1
2
3
33 34