0

I wonder how many and how big strings I can save using UserDefaults.standard

Eg:

static func saveUsername(_ token: String) {
        userDefaults.set(token, forKey: "username")
        userDefaults.synchronize()
    }

I want to save my users: username, email, address(state,city,street), first name, last name

But I am not sure how big/how many strings I can save or what kind of impact it has on my app storing many strings

Kiow
  • 870
  • 4
  • 18
  • 32
  • See http://stackoverflow.com/questions/7510123/is-there-any-limit-in-storing-values-in-nsuserdefaults You can save tens of megabytes of data. It's just a file. – Sulthan Mar 30 '17 at 21:34
  • 1
    Keep in mind that UserDefaults is just a file, so it needs to read and write the whole thing whenever you do anything with it. You don't want it to get too big. – Andy Ibanez Mar 30 '17 at 21:37
  • To add to previous comments, if it's too big, you need to use core data. – Milad.Nozari Mar 30 '17 at 22:20
  • Related http://stackoverflow.com/questions/10262654/maximum-size-of-objects-that-can-be-stored-in-nsuserdefaults – Ahmad F Mar 30 '17 at 22:47
  • Recommended reading https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html – Leo Dabus Mar 30 '17 at 23:17
  • You *can* save as much as you want, but you should **not**. The bigger the file is, the slower the defaults sync is. This is meant for storing tiny values. For anything else than a few text/numerical values, use proper storage, not defaults. – Eric Aya Mar 31 '17 at 10:33

0 Answers0