Questions tagged [userdefaults]
507 questions
0
votes
2 answers
Swift3: Error in TableView when deleting cells holding UserDefault values
I followed all steps provided here: The proper way to delete rows from UITableView and update array from NSUserDefaults in Swift / iOS
However, an error is caused, saying;
'Invalid update: invalid number of rows in section 0. The number of
rows…

Ryo
- 83
- 11
0
votes
2 answers
Saving data with User defaults
I am making a feature in my app that allows you to mute the music, i put a switch there so you can change it between on and off. However, the switch works fine in the app, when i close the vie controller and i pull it back up it will still show it…

Oren Edrich
- 674
- 1
- 7
- 23
-1
votes
0 answers
How to protect app fintech data stored in Keychain or User Default cannot be transferred, after user using the new iPhone transfer feature in iOS
iOS provide feature able to user to transfer data to new iPhone or iPad
So after transfer data to new iPhone all the app data will be transfer all
As developer want to build app which is secure for user to protect all data
Store in keychain, or…

Seak
- 59
- 2
- 4
-1
votes
1 answer
UserDefaults, ObservableObject and SwiftUI
I'm a little confused on how ObservableObject works with UserDefaults and could use some assistance.
I have a data struct that I need to save when a Background Fetch task runs. When the user resumes the app, I want the new data to be displayed.
As…

FlatDog
- 2,685
- 2
- 16
- 19
-1
votes
1 answer
Swift line break not working after loading from UserDefaults
I'm loading a string from UserDefaults and set the text of a TextView to that string. When it includes a line break character, it will just display the line break character in the TextView and not an actual line break.
I save a short bio in…

Yoshua Kaempf
- 1
- 2
-1
votes
1 answer
How to archive and unarchive an SKPhysicsBody array using UserDefaults since iOS 12.0
I can successfully archive and unarchive an array of SKPhysicsBody's using UserDefaults as below but the unarchive process has been deprecated. This is the warning message...
'unarchiveObject(with:)' was deprecated in iOS 12.0: Use…

Guitarman4
- 33
- 5
-1
votes
2 answers
UserDefaults How can I get my own saved keys?
I tried this code but it brings me all keys saved except me. How can I get my own saved keys?
print("UD: \(UserDefaults.standard.dictionaryRepresentation().keys) \n")
Console:
The key I saved is "Ağustos Test 1".
How can I get only this key?

Ufuk Köşker
- 1,288
- 8
- 29
-1
votes
1 answer
UserDefaults to Image code builds, but crashes when ran
I am coming from reading code from a ton of StackOverFlow posts for what seems to be a rather simple procedure, but when I try to implement what I've learned in my own code it fails.
In my "ViewController" didSelectRowAt function, I initialized the…

ctm
- 88
- 1
- 1
- 10
-1
votes
3 answers
How can I append an new Element to an Array in the Userdefaults (SwiftUI)
I wanna have an String Array in the Userdefaults, which I can edit. That means I want to append new Items to this Array.Here is some example Code
var defaults = UserDefaults.standard
defaults.array(forKey: "myArray")?.append("NewElement")
But I get…
user14027307
-1
votes
1 answer
Saving string array to user defaults
I have read all the stackoverflow articles I could find about this but doing what they said for some reason does not work.
I would like to save an array of strings (1 string at a time) to user defaults then print out the entire array for my own…

Eric33
- 13
- 1
- 2
- 6
-1
votes
2 answers
Loading of strings via AppStorage across classes in SwiftUI
I'm trying to save strings in SwiftUI via AppStrorage, this works so far, but I would also like to be able to access and load this saved data in another class.
If someone can help me, I would be very happy.
thanks

Leo Saischowa
- 9
- 4
-1
votes
1 answer
Userdefaults doesn't load or save
I have a strange problem with UserDefaults: Sometimes it can save and load but sometimes it doesn't work.
class ViewController: UIViewController {
@IBOutlet var text: UITextField!
var savedArray : [String] = []
override func…

Coco jombo
- 51
- 1
- 6
-1
votes
1 answer
How to update viewcontroller
I’ve put code in ViewWillAppear and I’ve tried ViewDidAppear but the app only updates when I close it and re-open it. Anyone have any idea on how to fix this? I’m using UserDefaults to update the app with. I’m new to swift and I’m using storyboard…

Jamesnjones
- 41
- 6
-1
votes
2 answers
How to implement userDefaults with a Global Variable array
I have an empty array set as a global variable that is populated with array items from a tableview. This is used to populate another tableview. This data needs to persist so that when the user returns to the app, their tableview data is in the same…

pretz
- 232
- 2
- 14
-1
votes
1 answer
Attempt to insert non-property list object error while storing dictionary in userdefaults
I have a dictionary with type of [Int: [Int]], I want to store it in user default.
The key of dictionary is like that : 1100110004
and the value:
[1,2,0,0]
But I got this error:
Attempt to insert non-property list object {\n 1100110004 = …

Peter hes
- 101
- 6