Questions tagged [userdefaults]

507 questions
2
votes
2 answers

Save string from TextField in UserDefaults with SwiftUI

How can the string from a TextField be stored in UserDefaults using SwiftUI? I have seen this tutorial on how to save the state of a toggle in UserDefaults and that looks promising, but I can't figure out how to use the same idea for storing the…
oscar
  • 33
  • 1
  • 3
2
votes
0 answers

SwiftUI ForEach loop not updating from ObservableObject

I started playing with SwiftUI in the last few days and it makes a lot of sense. However, I'm struggling when it comes to updating a persisting list. I'm using UserDefaults and JSONEncoder. struct ContentView: View { private var slackController…
Daniel P
  • 2,439
  • 3
  • 20
  • 27
2
votes
1 answer

Unable to decode data Swift

I saved some values in UserDefault and I am trying to get it back but I am unable to decode it as it keeps returning fatalError func save(dataPass: FeaturedProperties) { var saveArraData: [FeaturedProperties] = getAllData() …
King
  • 1,885
  • 3
  • 27
  • 84
2
votes
2 answers

Removing Suite in UserDefault

var sharedPreference : UserDefaults = UserDefaults.init(suiteName: "userKeyValue")! I am creating UserDefault instance like this and most probably it is creating a space in device with name userKeyValue and keep all key value pairs in that. Now…
RateM
  • 241
  • 1
  • 4
  • 15
2
votes
0 answers

Changing app icon doesn't work when saving user defaults

In a secondary view controller in my app, I have a table of icons to change to, like the Reddit app Apollo. In my main view controller, I am using user defaults to save two labels text and the view background color. Without any user default saving…
956MB
  • 135
  • 2
  • 12
2
votes
6 answers

How to count how many times all classes are called

I want the user to be able to know how many times they have visited each class. Then add together the totals from each page together to form a group sum. I want to print the total sum in the log file in each of the two view controllers. So just one…
user8105388
2
votes
1 answer

Where is the UserDefaults data stored when sharing it with app and extension?

I have created an application which uses "UserDefaults" for storing the data. I am using the App Groups capability to share the data between the host app and extension. Where can I see the data stored in it? When using the default…
subin272
  • 733
  • 6
  • 24
2
votes
0 answers

Possible to export userdefaults plist as email attachment in Swift?

In Xcode userdefaults are saved in a plist. I'd like to export this file directly. Is it possible? There are a couple of answers on finding it in the simulator, but I'm interested in finding it on the device while using the app and attaching it to…
TaiBD
  • 53
  • 7
2
votes
2 answers

How to save and load array of objects - Swift 4

Here is my code from my app called Reminders: Folder Class: class Folder { var name: String var labelName: String var imageName : String var colour : ColourTheme var colourArray : Array var maxNumOfPages : Int …
2
votes
1 answer

Why does the URL get truncated when stored then retrieved from a local file system?

I have generated a URL with the following function below. I would like to save this to the local folder for use later on. However, when I save it to the local folder, and then retrieve it, the URL is truncated. Please can someone advise on how I…
dean
  • 321
  • 3
  • 17
2
votes
0 answers

Swift 4 User Defaults crash when setting Array of strings

I try to set an array of strings to UserDefaults but my app gets frozen at that point. I have no problem to set others kinds of data (like String and Bool). I have read this topic and others post elsewhere stating it could be problematic depending…
Trichophyton
  • 625
  • 5
  • 21
2
votes
3 answers

How to safely unwrap a value from user defaults?

if let seen: Bool = defaults.bool(forKey: UtilitiesKeys.mainTutorialSeen) { return seen } return false if i do this swift shows me an issue: Conditional cast from 'Bool' to 'Bool' always succeeds, Non-optional expression of type 'Bool' used…
2
votes
1 answer

swift Xcode reading application settings

I am new to swift/ios programming. I created a small app with settings but I can't seem to read value. UserDefaults.standard.register(defaults: [String : Any]()) let settings = UserDefaults.standard; let k =…
Nite
  • 443
  • 1
  • 6
  • 11
2
votes
1 answer

ReactiveKit Bond KVO observe UserDefaults

I was previously using RxSwift and I decided I did not want to use it anymore and was able to convert everything over to Bond which I am much more familiar with. Since the new changes though to Bond v5, I cannot seem to figure out how to observe…
Olyve
  • 701
  • 1
  • 8
  • 27
2
votes
1 answer

Easy way to remove UserDefaults (without coding)

I've seen that there are several ways to remove the UserDefaults via code. I've deleted a testing app from my phone but the UserDefault values are still there. Is there an simple way of removing the UserDefaults instead of implementing a function to…