Questions tagged [userdefaults]
507 questions
-1
votes
1 answer
Retrieving textFields data using userdefaults
import UIKit
class ViewController: UIViewController
{
var data : [String] = [""]
@IBOutlet weak var firstName : TweeActiveTextField!
@IBOutlet weak var lastName : TweeActiveTextField!
@IBOutlet weak var dateOfBirth :…

Madhu
- 9
- 2
-1
votes
1 answer
How to save class in swift to userdefaults without arguments
I was unable to find a suitable community to post in, so I am sorry if this is off-topic. I am having trouble saving a custom class in swift to userdefaults. Every other answer I have seen requires initializing the class with arguments but I am…

iamPres
- 83
- 5
-1
votes
1 answer
Storing collection of custom objects where each I stored in keychain
I have a password managing app. Currently, I store all of the user's accounts (i.e. Netflix, Spotify, etc) in an array that is then stored in User Defaults. Now, I want to make things more secure by storing each account in iOS keychain. I realized…

ncooke3
- 548
- 3
- 10
-1
votes
1 answer
Saving UIColor within Struct Array to UserDefaults
I have tried to implement the solution by Vadian here: Make UIColor Codable
But I am getting an error that I haven't been able to overcome.
Here is my implementation of the above mention solution:
struct Color : Codable {
var red : CGFloat =…

Freedlun
- 79
- 10
-1
votes
1 answer
Save a Codable to UserDefaults and matching the look of NSCoding
I have a struct called Station that supports the Codable protocol. Since it is a struct, it cannot support the NSCoding protocol. I would like to save an array of these Stations to the UserDefaults. I have code that does it without any…

Erik Allen
- 1,841
- 2
- 20
- 36
-1
votes
2 answers
UserDefaults Swift
I have question regarding UserDefaults.
Is it possible to store several fields in userdefaults? I am gonna show a sample example below code
fistname = UserDefaults.standard.set(name,forKey: "namekey")
fistnameone =…

Manognya
- 1
- 2
-1
votes
2 answers
Saving and retrieving a struct which is not codable to Userdefaults in Swift
I want to save a struct which can not be modified to UserDefaults in my code. I went through a number of solutions but everyone is advising to use Codable/NSCoding in the struct. I can not edit the struct. Does anyone have an idea how we can achieve…

iOSManiac
- 139
- 1
- 11
-1
votes
1 answer
How to save a server response array in UserDefaults for later use in Swift?
when a user login, I get an answer from server that contains an array like this:
{"answer":{"id":26,"username":"iosuser","address":"iosios","phone_number":"123123123","email":"gmail@gmail.com","created_at":"2019-02-02…

Jessica Kimble
- 493
- 2
- 7
- 17
-1
votes
1 answer
Type casting value from UserDefault throws error
I am trying to fetch a data from UserDefault but when I am doing this I am getting error
var sharedPreference: UserDefaults = UserDefaults.init(suiteName: "user-key-value")!
func getLastLoginClientId() -> Int64? {
for (key, value) in…

Shubham Agarwal Bhewanewala
- 1,119
- 1
- 8
- 20
-1
votes
3 answers
save and retrieve array to user default using swift
I want to save array from json to user default, I'll get the array when I print it. When I retrieve it in different view controller I only get the last array.
So how to retrieve all data user default in different view controller.
This is how I save…

edo oktarifa
- 63
- 1
- 13
-1
votes
1 answer
Swift - Best way to Save and later get a bunch of Data
i have the following case to achieve:
I have an UITableView with a List of some Data (Strings), if i tap on a row, i want to see all the Details of the Data. The Data should be added by the User. (TableView Stuff already knowing) i just want to…

Victor Lobe
- 3
- 1
-1
votes
3 answers
UserDefault is not saving the value
I have a survey form that appear only if the user still didn't answer survey every time the user launch the app. But even if I already answered the survey still its appearing. Here's how I'm doing it
//Get if questionaire is done
let defaults =…

user9900611
- 9
- 1
- 5
-1
votes
3 answers
Subclassing UserDefaults
tldr; why do we always use UserDefaults.standard instead of subclassing UserDefaults to make something that more precisely fits our needs?
Has anyone out there subclassed UserDefaults before? Or is that considered bad practice?
Say, for example,…

SleekDiamond41
- 11
- 2
-1
votes
2 answers
Appending String to UserDefault Array
Hey guys so I know that we can append single string to userdefault but I was wondering how we can append [String: String]
So here is my code
var savedArray = UserDefaults.standard.array(forKey: "array1") as! [String]
let name = John
let…

Dkeem
- 9
- 5
-1
votes
1 answer
How can I check UserDefaults after terminate and reopen an app in Xcode (swift)
I archived an object which adopted Codable, and implemented storing the object data when the app enters background, loading them when the app is reopened.
But it doesn't work.
How can I check the UserDefaults' changes after terminate and reopen the…

undervine
- 59
- 6