Questions tagged [userdefaults]

507 questions
-1
votes
1 answer

Persist and retrieve UserDefaults between VC in a UITabbar

I have a TabBar app with 3 VCs. The first one displays a UIPickerView thatallows the user to select one of three languages, and label texts are translated depending on the language chosen. I persisted the chosen language with UserDefaults, no big…
-1
votes
1 answer

How to use User Default?

Sorry if this is a newbie question, I am very new to iOS & Swift. I have seen already on the internet how to use User Default, but I don't know how to insert it in my project: @IBOutlet weak var labelScore: UILabel! var score = 0 let…
Edoardo
  • 657
  • 7
  • 24
-1
votes
2 answers

Using UserDefaults to save a high score in swift

I"m trying to get a high score to save each time the player exits the app, but I'm struggling to get it to work and I'm confused as to where I'm making a mistake. var gameSettings = Settings.sharedInstance let HIGHSCORE = "HIGHSCORE" if…
ahuddle9
  • 3
  • 1
-1
votes
1 answer

Swift UserDefaults (2017)

I'm new at Xcode and currently making an app, where you have an amount of "bananas / money", whereof you can flip a coin, and you either win 2x or lose your bet. (Just for experience) My game is fully working, I've now just decided, that I want to…
-2
votes
0 answers

Why does this scenario break UserDefaults?: UserDefaults values not available on 2nd+ call of viewWillAppear/viewDidAppear

Edit: The HOW is not important, I'm interested in the WHY. Here is a scenario that triggers the WHAT: I am loading a simply boolean value from UserDefaults.standard in my ViewController's viewWillAppear method. I do not alter or delete the data, I…
smakus
  • 1,107
  • 10
  • 11
-2
votes
2 answers

Error when trying to set array in userdefaults: Thread 1: "Attempt to insert non-property list object

I have solved the issue now, thanks for your help. I shouldn't have tried to save arrays with UITextViews, but I should have saved their text as strings instead. Here was the original question: I have tried a lot, and googled a lot, but I can't…
Gabriel
  • 37
  • 4
-2
votes
2 answers

Get first entry in Swift array

I can't seem to find much online, but how can I get the first (and then second and third, later on) entry of an array? My array is being saved to UserDefaults elsewhere and then pulled for use here. Thanks!
Noah Evans
  • 309
  • 3
  • 12
-2
votes
1 answer

Are you able to retrieve data stored in UserDefaults across different View Controllers/.swift files?

I created a string value and stored it in a UserDefault on one view controller like so: letSwimmerOneName = "John" UserDefaults.standard.set(String(swimmerOneName), forKey: "twoFreelayNameOne And I'm trying to retrieve that data on a different view…
Leo Marcinkus
  • 78
  • 1
  • 7
-2
votes
2 answers

What is the proper event to save data using UserDefaults?

I'm new to ios. I have a view controller and some data object in it. I want to save data to UserDefaults before the view controller is disappear. In android I used "On stop" event and so on. What is the proper event in ios? I thought about saving…
Dima
  • 1,189
  • 1
  • 8
  • 12
-2
votes
1 answer

Userdefaults set in controllerA cannot to read in ControllerB

i am setting the user information in signInController. signupController needs to populate the same information if any mandatory fields are missing or the data needs to be updated,but the user default is nil when retrieved from in…
uma
  • 9
  • 1
  • 6
-2
votes
2 answers

Determining Swift Types That Can Be Stored in UserDefaults

I am in the beginning stages of developing an open-source utility for storing state in the Bundle UserDefaults. I'm encountering an issue when I add non-Codable data types to my Dictionary of [String: Any]. I need to be able to vet the data before…
Chris Marshall
  • 4,910
  • 8
  • 47
  • 72
-2
votes
2 answers

Update View every day

looking for a possibility to update the view every day. this is what I have tried... but it doesn't even print "test2" var WordNumber = 0 override func viewDidLoad() { super.viewDidLoad() let userDefault = UserDefaults.standard if let…
rabest97
  • 5
  • 2
-2
votes
1 answer

Store UIImagePickerController Image locally in App Assets

I'm trying to assign a profile picture in app through a UIImagePickerController. However, I need to figure out a way to store the image so it still appears after the apps restarts. I've tried other methods, primarily the ones that use…
-2
votes
2 answers

Trying to add multiple Uitextfields as integers

I am having trouble turning my Uitextfields into integers. I am trying to add them to get a total score for hole 2 and hole 3? Do you all have any ideas? I have tried Int(hole.text) and many other variations, but i keep getting errors. // // …
-2
votes
2 answers

Swift user defaults - array

Getting error on the below code as Binary operator '==' cannot be applied to operands of type '[String]?' and 'String' func loadDefaults() { let userDefaults = UserDefaults.standard.object(forKey: "storedArray") as? [String] if…
Sureshtrb
  • 51
  • 11
1 2 3
33
34