Questions tagged [userdefaults]
507 questions
0
votes
1 answer
Boolean value obtained from UserDefaults printing as 0 or 1 even when saved as Any
I am saving a dictionary of type [String : Any] to UserDefaults,
When I print the dictionary before saving to UserDefaults, the boolean value from the dictionary prints as true or false, However when I retrieve the dictionary it prints out as 0 or…

SpaceX
- 2,814
- 2
- 42
- 68
0
votes
1 answer
Persisting data in iOS app
I am new to iOS. I want to save authentication token recieved from a REST API to use in further api calls without requiring a login. Currently I am using UserDefaults to store this token. This token works fine unless app is completely closed.…

Nauman Zafar
- 1,083
- 15
- 40
0
votes
3 answers
How to store an updated set of questions and answers in iOS/Swift and persist it
I'm starting a relatively simple app which presents a series of multiple choice questions. There will be 4 possible answers (A/B/C/D) and more than one choice can be correct. While manipulating such an object (one instance of a question with its…

laurie
- 965
- 1
- 11
- 21
0
votes
2 answers
How to user UserDefaults to Save Logged in state?
i'm making introdution for my app, in swift 4 but i ran intro a problem. i have a introController and HomeController view,root view is introController so i want if user logged in to HomeController from introControll, then Whenever user open app, the…

Ngô Anh Duy
- 1
- 1
- 1
0
votes
1 answer
How to change the type of a value from UserDefaults?
I'm trying to compare a value that was saved to UserDefaults to a new integer but I cant figure it out.
func setScore() {
let defaults = UserDefaults.standard
let newScore = score
if defaults.object(forKey: "HighScore") != nil {
…
user8537717
0
votes
2 answers
UserDefault values are missing
I want to save some values in UserDefaults. And I am using this code to save
func SaveSettings(){
let def = UserDefaults.standard
def.set("test", forKey: "Value1")
def.set(myString, forKey: "Value2") //value: test1
def.set(myInt,…

Ekrem Duvarbasi
- 189
- 1
- 7
0
votes
1 answer
How do you save user answers received from a textField on a tableView using Swift
I have made a little quiz where a tableView holds different questions and answers as labels and textFields.
If the correct answer is entered the tableView cell turns green,the textField Text is set, and the textfield becomes uneditable.
My problem…

lisen kaci
- 151
- 1
- 12
0
votes
1 answer
Issues with userdefaults usage swift 3
I just started learning Swift so the level of this question may be obvious enough for you, however, I simply can't understand what to do.
I "created" a simple app which allows you to add logs of your day. Each cell stores the time you added, a…

Lucas Haas
- 331
- 1
- 2
- 15
0
votes
2 answers
How can I keep track of data moving with dates?
I have a school app that keeps track of your schedule. The app has a multitude of options for inputting the schedule. If the user has a four day schedule, then they will have A-D days. For my app. I’d like to keep track of what the current day is…

Ethan Humphrey
- 1
- 3
0
votes
0 answers
Cannot save data to shared preferences / user defaults of app group
I need to save some settings which should be shared among two apps. To achieve this I activated App Groups in the capabilities of both apps and set the App Group to TeamIdentifierPrefix.name.appname.
The relevant code to save the data in the user…

northsea
- 152
- 1
- 8
0
votes
2 answers
How to save model class in UserDefaults with static self instance?
I have a model class User that I want to save in UserDefaults
import UIKit
class User: NSObject {
var name:String!
var email:String!
var userId:String!
var phone:String!
var admin_status:String!
var social_code:String!
…

Varun Naharia
- 5,318
- 10
- 50
- 84
0
votes
2 answers
Why does my User Defaults bool not set on first launch of app?
I have a UserDefault Bool for music playing.
When launched for the first time, I attempt to set the bool to true, like this...
if launchedBefore {
// Do nothing.
} else {
UserDefaults.standard.set(true, forKey: "musicOn")
…

Khoury
- 411
- 1
- 4
- 21
0
votes
0 answers
Swift compiler throws an error after archiving custom class data to UserDefaults
I have an array of bank cards and want to save it once in order not to download data from server several times. So, the problem is that I can't archive objects of class "Card" that I declared. Card class consists of four fields as you can see and I…

Kirill Korolev
- 966
- 3
- 9
- 22
0
votes
2 answers
Present log in screen only if there are no data stored in user defaults
I have an app which stores user data (mail and password) using UserDefaults. Once the user sends this information, next time he/she opens the app, the app should not show the registration view (as long as the user data is recorded).
I think this…

Daniel C.
- 151
- 1
- 2
- 10
0
votes
0 answers
Swift 3 User Defaults set dictionary crash
I have worked with Userdefaults many times before but in this case can't seem to figure out what would cause this crash to occur even though it is such a simple case.
Goal: UserDefaults.standard.set a dictionary with a value of an array of…

lifewithelliott
- 1,012
- 2
- 16
- 35