NCFUSN
NCFUSN

Reputation: 1644

where to save 100 NSStrings + other type

I need to save somewhere 100 strings (quiz questions iphone app). Also, some datatype which will store the the information if the right button was pressed. What is the best way to store these values, in NSArray, NSMutableArray or in .plist?

Thank you in advance

Upvotes: 0

Views: 72

Answers (2)

alloc_iNit
alloc_iNit

Reputation: 5183

For each separate question create an NSMutableDictionary and store it into NSMutableArray is the best way to work with such process.

Code for reference:

    NSMutableArray *arTemp = [[NSMutableArray alloc] init];
    for(int i =0; i < 10; i++)
    {
            NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
            [tempDict setObject:@"object1" forKey:[NSString stringWithFormat:@"value%i", i]];
            [tempDict setObject:@"object1" forKey:@"type"];
            [arTemp addObject:tempDict];
            [tempDict release]; 
    }

Is that clear to you?

Upvotes: 0

Nathan Day
Nathan Day

Reputation: 6037

You can use a PList to add the data to you project and then load them into you NSDictionary, you can read in a PList into a NSDictionary with -[NSDictionary initWithContentsOfFile:]

Upvotes: 1

Related Questions