0

I am firstly new to SO and new to iOS Development. I have completed the CS193P course on iTunes and am ready to tackle my first proper app. I have the prototype set up and just need some reference pointers on where to begin (need that confidence).

The premise of the app is to allow the user to add entries to 1 of 2 available lists; either a giving or a receiving list. The entries will include things like "Name of Event", "Name", "Date" etc. There will also be an option for the user to of course go through the lists and see the entries; I want to allow the user to choose whether they search by name, date or event.

I've got the prototype set up completely and I am just wondering if this kind of application would be somewhat considered similar to an Address Book? The user can add the name of the person (or select the name from contacts), etc.

Apologies for our outstandingly basic question here, but does anyone have any good reference points for essentially, creating a list of entires that get appended to a specific list. I have familiar with Modal View Controllers and the delegates; I'm basically wondering what I should use to "store" the entires the users add. Should I use Core Data or some other technique, etc?

Thanks! Amit

amitsbajaj
  • 1,304
  • 1
  • 24
  • 59

3 Answers3

0

Yes you have to use Core Data to store the entries. Otherwise whenever the user reopens the app all the entries will be gone.

s_curry_s
  • 3,332
  • 9
  • 32
  • 47
0

I've been using NSKeyedArchivers to store lists. http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSKeyedArchiver_Class/Reference/Reference.html

Very easy to manage, and it can store, save, and retrieve all your data easily.

Example would be a list (NSMutableArray) of objects. Each object implements NSCoding and has the initWithCoder: and encodeWithCoder: functions.

e.g. (assuming the objects have a name and date property)

- (id) initWithCoder:(NSCoder *){
    self = [super init];
    if (self){
        [self setName:[aDecoder decodeObjectForKey:@"name"]];
        [self setDate:[aDecoder decodeObjectForKey:@"date"]];
    }
    return self;
}
- (void) encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:name forKey:@"name"];
    [aCoder encodeObject:date forKey:@"date"];
}

Then you could simply have your NSMutableArray which you add these objects to, managed by something which has the following functions, and just call saveChanges on it:

- (NSString *) itemArchivePath{
    NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentsDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [documentDirectories objectAtIndex:0];
    return [documentDirectory stringByAppendingPathComponent:@"myArchiveName.archive"];
}
- (BOOL) saveChanges{
    NSString *path = [self itemArchivePath];
    return [NSKeyedArchiver archiveRootObject:myList toFile:path];
}

With those two functions implemented, you can just call saveChanges.

And to Retrieve the list later after the next startup, in your manager's init:

- (id) init{
    self = [super init];
    if (self){
        NSString *path = [self itemArchivePath];
        myList = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
        // If the array hadn't been saved previously, create a new empty one
        if (!myList){
            myList = [[NSMutableArray Alloc] init];
         }
    }
}
Doc
  • 1,480
  • 2
  • 16
  • 28
  • Thanks Doc for your answer. That does help and while I have heard of NSKeyedArchivers, I have not dived into it but looking at your code, it doesn't look too difficult. I'm weighing this out between Core Data but thanks very much for your answer; I will certainly be investigating this. – amitsbajaj May 09 '13 at 07:56
0

Your question is very general, so here is my general answer: I would recommend using Core Data to store the lists, and an NSFetchedResultsController to display them. I would also recommend you have a look at the free Sensible TableView framework, which I use regularly to automate tasks that are very similar to the one you have at hand.

Matt
  • 2,391
  • 2
  • 17
  • 18
  • Thanks Matt - that is very helpful and I will indeed look at that framework. My apologies for the general question - it's still formulating in my head but good to know Core Data is the way to go and NSFetchedResultsController will be the way to retrieve it. – amitsbajaj May 09 '13 at 07:54