0

I am making a note-taking app but this app won't be a traditional note-taking application. This application will be used by my company's employees and engineer teams in my company. The notes content will be large because contain some mathematical expressions. Also, files must be sent to dropbox as text and pdf files.

I wonder which is the best method of these for storing large data content:

1- Simply writing notes content to file (like note1.txt) in Documents directory

I am using this function for writing files:

-(IBAction)writeFile:(id)sender
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fileNameData=[NSString stringWithFormat:@"%@.txt",fileName.text];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileNameData];

    NSString *str = fileContent.text;

    [str writeToFile:filePath atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];
} 

2- Or storing file contents in database and create a file when user wants to send the note to dropbox and send this created file to dropbox?

I have created note-taking apps before but in this one, files will be large and I am worried about performance.

UPDATE

I did some trials. I tried to write and read the same string using both technique; core data and files.

It takes about 16 seconds to read string from Core Data and about 5 seconds to read from the file with stringWithContentsOfFile method.

I know that is not very accurate results but I guess Core Data is not very proper for me. If I am wrong, please correct me.

amone
  • 3,712
  • 10
  • 36
  • 53
  • Core Data is the Good option to store the Large data.For reference see this Link its Helpful. http://stackoverflow.com/questions/15788414/insert-a-pdf-file-into-core-data – Sandeepk2r Aug 02 '13 at 06:50

3 Answers3

1

Well this should be done using core data Core Data Usage and for the benefits please read this SO question Why should I use Core Data for my iPhone app?

I made a Notes App myself and used core data and it works fine . Hope this helps.

EDIT : Or check this link Relating to the Data Storage guidelines. It includes all types of guidelines as given by Apple.

Community
  • 1
  • 1
IronManGill
  • 7,222
  • 2
  • 31
  • 52
  • To be honest, the described problem is the perfect example where one should NOT use Core Data: 1) There are "large" data blobs which should not go into the persistent store, and "notes" are presumable simple objects with just one immutable value: text. Thus, the cool features Core Data has wont't be used at all. – CouchDeveloper Aug 02 '13 at 07:03
  • I don't understand what you mean with "persistent store"? The notes aren't persistent data? – amone Aug 02 '13 at 20:31
  • @charty Well the app I gave as an example pls test it and you will see the use of core data ..... – IronManGill Aug 03 '13 at 05:07
0

Core data is a pain the in butt to get setup and working. Do you have a incredibly large data set or need to do entity relationship between the files?

If not I would just have a dictionary or array that contains a simple object that has meta data about the file (last access time, title, file location, etc) I would then load this dictionary and use it in a table view for selecting the files.

The files themselves can be loose files on disk in the data directory. To improve the performance of saving just copy the string and then just write it out asynchronously using GCD. When a user selects one file to open again load it using GCD and show a small progress bar. if these files are small it will be close to instant for loading.

odyth
  • 4,324
  • 3
  • 37
  • 45
  • I haven't used Core Data before and I am a little confused now :) Our files sizes are approximately 500 KB. We read and edit files very frequently so I am looking for the best solution. Do you suggest GCD for this size? – amone Aug 02 '13 at 08:36
  • I don't need to do complex relations between the files. I need to store only note title, note content and creator name. – amone Aug 02 '13 at 08:40
  • If your just storing the note in a string you can use GCD and kick it off into a serial background queue for writing. The serial queue will make sure the rights happen in order that way you dont have to worry about canceling writes in progress. When the block copies your string object you might notice a little bump in memory, but it shouldn't be too bad. – odyth Aug 05 '13 at 07:01
  • Core Data is way overkill for small data sets especially ones that don't need complex relationship mapping. That is what apple told me at WWDC 2013. – odyth Aug 05 '13 at 07:02
  • Why you suggest me to use GCD? Can you explain briefly what are the benefits of using GCD for writing files? – amone Aug 05 '13 at 10:15
  • GCD = Grand Central Dispatch is apples multithreading framework. you shouldn't write to disk on the main thread as it can lock up the UI. I am recommending that you wrap your write call in a dispatch_async to a serial background queue. – odyth Aug 08 '13 at 06:51
0

CoreData would be quicker than read/write to files. But, you are not worried about performnace when you write to file. You are worried about Performance when you send the files to dropbox How frequent is that? If that is done not so frequently like once a day , then may be text files is a better option than coredata or sqlite.

zahreelay
  • 1,742
  • 12
  • 18
  • Yes, we use dropbox frequently, actually 3-4 out of every 10 files are stored in dropbox. – amone Aug 02 '13 at 08:31