Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much data can I store in NSUserDefaults? [duplicate]

I know that NSUserDefaults isn't ideal for storing a large amount of data, but I don't know what the actual limit is. Which made me thinking ...

1. Is there a recommended size limit?

2. Is there a way to see the size of the data I'm storing?

In this case, I'm thinking of using NSUserDefaults to store an array of strings.

like image 906
Christofer Vilander Avatar asked Jan 06 '23 11:01

Christofer Vilander


2 Answers

It appears the limit is the maximum file size for iOS (logically), which is currently 4GB: https://discussions.apple.com/thread/1763096?tstart=0. The precise size of the data is circumscribed by the compiler types (NSData, NSString, etc.) or the files in your asset bundle.

I am sure there is low-level documentation on Swift types somewhere--but you will need to discover it yourself. :)

I have not redirected to another answer because similar questions also suggested that the limit is the device size.

Be aware that NSUserDefaults is considered harmful for large files, because all defaults are loaded immediately at application launch. Access time will be slow, performance will be impacted. Consider using a structured storage medium, such as Core Data, CloudKit, or SQLite, for large files.

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/nsfetchedresultscontroller.html#//apple_ref/doc/uid/TP40001075-CH8-SW1

https://developer.apple.com/icloud/

http://www.appcoda.com/sqlite-database-ios-app-tutorial/

like image 100
manglano Avatar answered Jan 17 '23 21:01

manglano


I think as long as there is enough space on your device you can store all of the data you wants... The device is the limit.

NSUserDefaults values are stored into a .plist file:

See this post to know where: Get NSUserDefaults plist file from device

like image 20
Thomas Avatar answered Jan 17 '23 20:01

Thomas