Sunday 15 February 2015

ios - NSUserDefaults causing performance issues -


I believe that due to the excessive use of NSUserDefaults I have CPU performance issues, is it possible? I'm debugging some code that has used it to store a lot of user data and are now talking on the next call 4 seconds per call to store the data. What will be the reason for these long delays?

  // Save data in user data; NSDate * timerStartTime = [NSDate date]; NSLog (@ "data size% lu", (unsigned long) [resulted in datatata length]); [Auto set object: result.data forkey: defaultName]; NSTimeInterval elapsed = [[Date of NSDT] TimeInternational Censor: Timer Starttime]; NSLog (@ "Time for Function:% f", elapsed);  

and output:

Time for function: 4.1

If you are collecting large amounts of data, then you should definitely not use NSUserDefaults to do this

NSUserDefaults for things like flags, simple settings, or user variables Good to use, like aliases, etc. Basically User Preferences

The reason for this is:

Ul>

  • NSUserDefaults are loaded and loads throughout its entirety.
  • NSUser Defaults are loaded on the application launch so that you can not thread its loading process.
  • The data store should be done using the core data:

    Or if it is the array of only one dictionary or array, you can use property lists :

    The data uses a pList to store NSUserDefaults so that you can come to some of the same limitations, but you will have greater control over when and how to write or read your data. Also, NSUser Defaults is not a good practice to use as a make-shift DB when it has a purpose for preferences.


    No comments:

    Post a Comment