سؤال

Hello everyone I would like to know what is the difference between NSUserDefaults and .plist file. Thanks in advance.

هل كانت مفيدة؟

المحلول

NSUserDefaults is also a PList but the main difference is that it is recommended to use NSUserDefualts for small data such as flags(for example "isUserLoggedIn" or "isFirstLaunch"), but use PLists for storing big hierarchal data.

Other than this You can store Plist in any location you want (allowed by iOS) but you cannot change the location on which NSUserdefauls are stored. It is defined by OS.

نصائح أخرى

You can think of NSUserDefaults as an invisible .plist that you can read and write to, without ever being able to actually see the file. Using NSUserDefaults, you will be able to restore saved values even if the app has been killed in multitasking. However, how you choose between .plist and NSUserDefaults should be based off of how much data you need to save. Apple recommends only saving small amounts of data to NSUserDefaults. If you need to save a lot of information then .plist is the way to go. Either that or of course Core-Data."

Reference : Difference between NSUserDefaults and .plist

Both things used to store the values . NSUserdefaults is easy to store the values..just single line you can store values...

To use NSUserDeafults or .plist(Property List) is base on your data, How much data you want to save.

NSUserDefaults is an invisible and .plist that you can read and write to, without ever being able to actually see the file.

If you have small number of data then store it in NSUserDefaults and If you have more data or information then store it in .plist file.

Thank you.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top