Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7016653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:48:48+00:00 2026-05-27T22:48:48+00:00

I’m developing an app which will save data to the local file system. The

  • 0

I’m developing an app which will save data to the local file system. The data that will be saved will be mostly NSString and NSDate. The data will not be saved that often, perhaps new data will be entered 10 times at a typical usage. The data should also of course be retrievable (CRUD)

How should I save this data? First of all is it necessary to model these objects? If not should I use property lists? Or SQLLite3?

Else should I archive the class models? Use SQLLite3?

EDIT: I accidentally left out some vital information about the app. Actually my app will be having 2 data models which have an aggregated relationship. So my first data model (lets call it DataA) which will have a NSString and NSDate will also have a reference to the second data model (lets call it DataB) which itself will consist of a NSString and a NSArray. So it gets a little more complicated now. If an object from DataB gets deleted it should of course cease to exist in DataA (but the rest of DataA should be left untouched)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:48:49+00:00Added an answer on May 27, 2026 at 10:48 pm

    This kind of data seems to be very simple to store and retrieve and does not have any other dependencies such as a horridly complex object graph.

    You should store this data in a flat file or in NSUserDefaults.

    I’ll give you an example of both, using object archiving with the use of the NSCoding protocol:

    @interface ApplicationData <NSCopying, NSCoding> {}
    
    @property (nonatomic, strong) NSDate *someDate;
    @property (nonatomic, strong) NSDate *someOtherDate;
    
    @property (nonatomic, copy) NSString *someString;
    @property (nonatomic, copy) NSString *someOtherString;
    
    @end
    
    @implementation ApplicationData
    
    @synthesize someDate = _someDate, someOtherDate = _someOtherDate, someString = _someString, someOtherString = _someOtherString;
    
    - (NSArray *)keys {
       static dispatch_once_t once;
       static NSArray *keys = nil;
       dispatch_once(&once, ^{
          keys = [NSArray arrayWithObjects:@"someString", @"someOtherString", @"someDate", @"someOtherDate", nil];
      });
       return keys;
    }
    
    - (id) copyWithZone:(NSZone *) zone {
        ApplicationData *data = [[[self class] allocWithZone:zone] init];
        if(data) {
            data.someString = _someString;
            data.someOtherString = _someOtherString;     
    
            data.someDate = _someDate;
            data.someOtherDate = _someOtherDate;
            //...
        }
        return data;
     }
    
     - (void) encodeWithCoder:(NSCoder *) coder {
         [super encodeWithCoder:coder];
    
         NSDictionary *pairs = [self dictionaryWithValuesForKeys:[self keys]];
    
         for(NSString *key in keys) {
            [coder encodeObject:[pairs objectForKey:key] forKey:key];
         }
      }
    
    
      - (id) initWithCoder:(NSCoder *) decoder {
         self = [super initWithCoder:decoder];
         if(self) {
            for(NSString *key in [self keys]) {
               [self setValue:[decoder decodeObjectForKey:key] forKey:key];
            }
         }
         return self;
      }
    
      @end
    

    Then, say in your application delegate, you can do this:

    @interface AppDelegate (Persistence)
    
    @property (nonatomic, strong) ApplicationData *data;
    
    - (void)saveApplicationDataToFlatFile;
    - (void)loadApplicationDataFromFlatFile;
    - (void)saveApplicationDataToUserDefaults;
    - (void)loadApplicationDataFromUserDefaults;
    
    @end
    
    @implementation AppDelegate (Persistence) 
    @synthesize data;
    
    - (NSString *)_dataFilePath {
       static NSString *path = nil;
       static dispatch_once_t once;
       dispatch_once(&once, ^{
         path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) stringByAppendingPathComponent:@"xAppData.dat"];
       });
       return path;
    }
    
    - (void)loadApplicationDataFromUserDefaults {        
       NSData *archivedData = [[NSUserDefaults standardUserDefaults] objectForKey:@"appData"];
       self.data = [NSKeyedUnarchiver unarchiveObjectWithData:archivedData];
    }
    
    - (void)saveApplicationDataToUserDefaults {
       NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:self.data];
       [[NSUserDefaults standardUserDefaults] setObject:archivedData forKey:@"appData"];
       [[NSUserDefaults standardUserDefaults] synchronize];
    }
    
    - (void)loadApplicationDataFromFlatFile {
       NSData *archivedData = [NSData dataWithContentsOfFile:[self _dataFilePath]];
       self.data = [NSKeyedUnarchiver unarchiveObjectWithData:archivedData];
    }
    
    - (void)saveApplicationDataToFlatFile {  
       NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:self.data];
       [archivedData writeToFile:[self _dataFilePath] atomically:YES];
    }
    
    @end
    

    Disclaimer: I have not tested this code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a reasonable size flat file database of text documents mostly saved in
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.