Questions tagged [swiftyuserdefaults]

SwiftyUserDefaults is a modern Swift API for NSUserDefaults

SwiftyUserDefaults makes user defaults enjoyable to use by combining expressive Swifty API with the benefits of static typing. Define your keys in one place, use value types easily, and get extra safety and convenient compile-time checks for free.

26 questions
5
votes
1 answer

Ambiguous type name error

I'm trying to re-compile SwiftyUserDefaults(https://github.com/radex/SwiftyUserDefaults) to add Carthage support, but on attempt to compile I see following error: Ambiguous type name 'Proxy' in 'NSUserDefaults' for following code public func ?=…
Alexey Poimtsev
  • 2,845
  • 3
  • 35
  • 63
3
votes
1 answer

Make SwiftyUserDefaults array accessible to iOS and watchOS app

I am using the excellent SwiftyUserDefaults, a wrapper for NSUserDefaults with Swift to allow my app to persist a certain array of data, like so (lots of code removed to show just the important parts: Working Code import SwiftyUserDefaults //The…
rocket101
  • 7,369
  • 11
  • 45
  • 64
2
votes
4 answers

How to mock and test a UserDefaults computed property that store String?

I am trying to mock UserDefaults to be able to test its behaviour. What is the best way to do it without corrupting the real computed property that save the user token key? class UserDefaultsService { private struct Keys { static let token =…
Roland Lariotte
  • 2,606
  • 1
  • 16
  • 40
2
votes
3 answers

Is it fine to access NSUserDefaults/UserDefaults frequently?

I have a login view controller in which the user enters their preferences like whether or not he wants to activate certain UI features. I store these as variables whose getters and setters directly access UserDefaults, here is an example of one of…
JoeVictor
  • 1,806
  • 1
  • 17
  • 38
2
votes
2 answers

Swift Adding Value to Existing User Defaults Value

I got User Defaults with the key "abc" for example and it contains a string. The last string stored in this key is "aaa". Now, I want to store an additional value for this key, but I don't want to delete the last value "aaa" because I need it. I…
Help Pleasee
  • 211
  • 3
  • 15
1
vote
1 answer

UserDefaults not saving when used in a framework

I have a framework that needs to save values locally, for that I chose UserDefaults. However, the values are never saved, and the following read function always return "" after restarting the app class Preferences { let preferences :…
Vanethos
  • 691
  • 1
  • 8
  • 20
1
vote
1 answer

How to reset the value of "AppleLanguages" key in UserDefaults

Initially, I have saved the value of 'AppleLanguages' key as 'en', and then when I tried to change the value as 'ar', but it still remains as 'en' I tried to clear the value to clearing the entire UserDefaults by uninstalling the application from…
Vinith
  • 119
  • 1
  • 6
1
vote
1 answer

Saving an array of objects in UserDefaults

Using swift 3.0, I'm trying to add an array of objects into user defaults. As this isn't one of the regular UserDefault types I've realised that the object or array of objects (can't work out which one) will need to be parsed to the type NSData to…
0
votes
1 answer

Can't save in Date format Custom default values ​swift

The structure stores the date value in the Date? format, but after saving it returns it in the timestamp format. if let data = try? JSONEncoder().encode(contact), let dict = try? JSONSerialization.jsonObject(with: data, options:…
Vladislav
  • 11
  • 1
0
votes
1 answer

How to clear the complete storage in UserDefaults without using removeforObject Method

i want to clear the complete storage in userDefault without using Remove Object method avaliable in userDefaults this is func i wrote but not sure is this the write way of doing it. public func cleanCompleteStorage(){ let domain =…
Wahid Tariq
  • 159
  • 10
0
votes
1 answer

Save array of different object types in UserDefaults

I have two classes, Radio and Podcast, children of the Media class. I'm trying to save an array of Media (with radios and podcasts) to UserDefaults but when I get it back, I only have medias (I'm losing information of Radio or Podcast). I cannot…
Edwin ZAP
  • 419
  • 1
  • 4
  • 16
0
votes
1 answer

Saving object containing sensitive data encoded as Data in user defaults

I have an object that contains sensitive data like pin code and password, and it is saved in user defaults as Data. Is saving an object as Data in user defaults is a safe decision, or would it be better to save the user object in keychain?
0
votes
2 answers

Why can we chain flatMap to UserDefaults.standard.data

In an article about UserDefaults in iOS development, I saw a code snippet where flatMap is chained to UserDefaults.standard.data like below: self.isReadStatuses = UserDefaults.standard.data(forKey: "isReadStatuses") .flatMap { try?…
pumpum
  • 555
  • 3
  • 5
  • 18
0
votes
0 answers

how to know the main app is running in keyboard extension?

I create a custom keyboard extension of main app. In the extension, i want to know if the main app is running? Is there any way to make it work? I have created the app group, and i share data with the UserDefaults var share: UserDefaults? =…
badboy_tqj
  • 300
  • 2
  • 14
0
votes
1 answer

How do I save input inside a UITextView?

How do I save input in a UITextView once my application is double tapped out/force quitted? Is there some code I can write on the textViewDidChange call that can automatically save the input? NOTE: The last code section is where the UITextView is…
1
2