ios - Storing in Plist? -


i wondering how 1 store data in plist, same output.right using nsobject. store these in separate dictionary's? how can call them fill tabledata array.

exercises *exercise1 = [exercises new]; exercise1.name = @"barbell rollouts"; exercise1.materials = @"30 min"; exercise1.imagefile = @"barbellrollouts.jpg"; exercise1.sets = @"2"; exercise1.reps = @"10"; exercise1.instructions = @"hello"; exercise1.status = @"dynamic";  exercises *exercise2 = [exercises new]; exercise2.name = @"barbell trunk rotation"; exercise2.materials = @"30 min"; exercise2.imagefile = @"barbelltrunkrotation.jpg"; exercise2.sets = @"2"; exercise2.reps = @"10"; exercise2.instructions = @"";   exercise2.status = @"dynamic";  exercises *exercise3 = [exercises new]; exercise3.name = @"bent knee leg raises"; exercise3.materials = @"30 min"; exercise3.imagefile = @"bentkneelegraises.jpg"; exercise3.sets = @"2"; exercise3.reps = @"10"; exercise3.instructions = @"";   exercise3.status = @"dynamic";  exercises *exercise4 = [exercises new]; exercise4.name = @"bicycle manouver"; exercise4.materials = @"30 min"; exercise4.imagefile = @"bicyclemanouver.jpg"; exercise4.sets = @"2"; exercise4.reps = @"10"; exercise4.instructions = @"";   exercise4.status = @"dynamic";  exercises *exercise5 = [exercises new]; exercise5.name = @"boat pose"; exercise5.materials = @"30 min"; exercise5.imagefile = @"boatpose.jpg"; exercise5.sets = @"2"; exercise5.reps = @"10"; exercise5.instructions = @"";   exercise5.status = @"static";  exercises *exercise6 = [exercises new]; exercise6.name = @"bosu boat pose"; exercise6.materials = @"30 min"; exercise6.imagefile = @"bosuboatpose.jpg"; exercise6.sets = @"2"; exercise6.reps = @"10"; exercise6.instructions = @"";   exercise6.status = @"static";   tabledata = [nsarray arraywithobjects:exercise1,exercise2,exercise3,exercise4,exercise5,exercise6,nil]; 

you need implement nscoding protocol

in header:

@interface exercise : nsobject <nscoding> // public property list @end 

in implementation file:

@interface exercise() // private property list @end  @implementation exercise  - (id)initwithcoder:(nscoder *)decoder {     self = [super init];     if (!self) {         return nil;     }      self.name = [decoder decodeobjectforkey:@"name"];     self.sets = [decoder decodeintegerforkey:@"sets"];     // similar approach other properties      return self; }  - (void)encodewithcoder:(nscoder *)encoder {     [encoder encodeobject:self.name forkey:@"name"];     [encoder encodeinteger:self.sets forkey:@"sets"];     // similar approach other properties } @end 

you should able use nskeyedarchiver save plist , nskeyedunarchiver read back:

[nskeyedarchiver archiverootobject:exercise tofile:@"/path/to/file"]; [nskeyedunarchiver unarchiveobjectwithfile:@"/path/to/file"]; 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -