1

As a newbie on iOS, I am devoloping a small app. There are 5 different pages and 4 of them has an imageView for user's profile photo, I am storing and downloading profile photo in Firebase.

Is it a bad practice to store the profile photo on userdefaults to not the download for each page that has imageView? I also have to store user's name as a string an a date (date of the user opened my app for the first time)

I know I got options like NSCache or Core data but UserDefault looks 10x time easier than them. I read on the internet that UserDefaults is only good for small amount of data, otherwise it will slow down my app performance, but they never mention how small.

So an image that has max 500kb size and a string with a date would be a performance problem? Is UserDefaults only for saving things like settings or a boolean for onboarding etc.?

traglen
  • 31
  • 5
  • Think hundreds of bytes, not hundreds of kilobytes. It's definitely not designed to be an image cache. Typically you would write this file to the filesystem and work with it from there, rather than NSCache or Core Data. – Rob Napier Dec 19 '22 at 16:38
  • For your specific there should be no problem if you store this into user defaults. Even if you are looking at much much larger data. But try to avoid this approach when for instance storing data for N users received from remote source. Alternatively you can also look into Codable protocol and save your data as JSON directly into files stored in documents directory. – Matic Oblak Dec 19 '22 at 16:38
  • Questions such as this are typically considered opinion based and might be removed by moderators. I recommend asking this question in the Ask Different community: https://apple.stackexchange.com/ – John Harrington Dec 20 '22 at 01:13

1 Answers1

1

Yes it is bad practice (and inefficient), UserDefaults is for small stuff like settings and preferences, small unimportant and low vulnerability stuff.

https://developer.apple.com/documentation/foundation/userdefaults

KeyChain is for small stuff that needs to be secure such as user data, tokens, etc.

https://developer.apple.com/documentation/security/keychain_services

Apple has provided other locations such as for "caching"

cachesDirectory

https://developer.apple.com/documentation/foundation/filemanager/searchpathdirectory

lorem ipsum
  • 21,175
  • 5
  • 24
  • 48