2

What is the best way to persist a small amount of user data in iOS 7? Is it a hack to use NSUserDefaults? Is CoreData too heavy?

I am attempting to store a list of airports that a user finds useful. The airports are identified by NSStrings and have a small amount of data associated with them.

I am not opposed to creating a Core Data app, I'm wondering what the best approach to persisting a small amount of data.

Kanan Vora
  • 2,124
  • 1
  • 16
  • 26
Chris Holloway
  • 247
  • 3
  • 10
  • 3
    Write the values to a plist file. Do some searching. You will find plenty of discussions on saving data in iOS. – rmaddy Jul 22 '14 at 04:51
  • As its array, you can simply write it to plist file. If you are holding the text in form of NSData, you can simply write it to file and read it as well. Check the documentation. – Satyam Jul 22 '14 at 05:11

4 Answers4

2

NSUserDefaults is persisting to a .plist file stored locally in your app bundle so no it's not a hack. The only problem with NSUserDefaults is that it is not easy to store custom objects. The supported data types are NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. If you need to store custom objects, Core Data is a better option but if you have just an array of strings and/or any of the above data types, then NSUserDefaults is the best way. It has a very simple API and is easy to manage.

Note: If you store an NSArray or an NSDictionary then any child objects also have to be of the above supported data types.

Milo
  • 5,041
  • 7
  • 33
  • 59
2

1)You can use plist files for saving the data by assigning the key value ,with help of the key we can get and save the value.[How to use pList in iOS Programming which given by @harry 2)Or you can use NSUserDefaults for storing the value the small amount of data .[http://ios-blog.co.uk/tutorials/quick-tips/storing-data-with-nsuserdefaults/] 3)Or you can use the sqlite3 for storing the Big amount of data .[http://www.raywenderlich.com/913/sqlite-tutorial-for-ios-making-our-app] 4)Or you can use core data for storing the big amount of data. [Good tutorials or good for using Core.Data in IOS 7

I hope it will help you

Community
  • 1
  • 1
Harish
  • 589
  • 5
  • 16
1

You can go for using plist files for saving such kind of data. You can write a array of airports into plist file.

Here's the link showing how to use the plist files: How to use pList in iOS Programming

Thanks.

Community
  • 1
  • 1
Harjot Singh
  • 6,767
  • 2
  • 38
  • 34
0

It depends on what you're doing with the data. NSUserDefaults can hold a lot more data than most people lead on, and it is very easy to use. If you're not storing a crazy amount of data or fetching it from a database, I would use NSUserDefaults.

Henry F
  • 4,960
  • 11
  • 55
  • 98