Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  2. NSString *documentsDirectory = [paths objectAtIndex:0];
  3. NSString *path = [documentsDirectory stringByAppendingPathComponent:@"plist.plist"];
  4. NSFileManager *fileManager = [NSFileManager defaultManager];
  5.  
  6. NSMutableDictionary *data;
  7.  
  8. if ([fileManager fileExistsAtPath: path]) {
  9. data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
  10. }
  11. else {
  12. // If the file doesn’t exist, create an empty dictionary
  13. data = [[NSMutableDictionary alloc] init];
  14. }
  15.  
  16. //To insert the data into the plist
  17. data[@"value"] = @(5);
  18. [data writeToFile: path atomically:YES];
  19. [data release];
  20.  
  21. //To retrieve the data from the plist
  22. NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
  23. int value1;
  24. value1 = [savedStock[@"value"] intValue];
  25. NSLog(@"%i",value1);
  26. [savedStock release];
  27.  
  28. 1. Right Click on Files in Left Pane and Select 'New File...' option.
  29. 2. Choose Resources from OS X tab.
  30. 3. An option for Property List is available.
  31. 4. Select an give an appropriate name.
  32.  
  33. NSString *path = [[NSBundle mainBundle] pathForResource:@"Priority" ofType:@"plist"];
  34. NSDictionary *dictPri = [NSDictionary dictionaryWithContentsOfFile:path];//mm
  35. NSMutableArray *arrMarkets=[[NSMutableArray alloc] initWithArray:[dictPri valueForKey:@"List"]];
  36. NSMutableArray *arrForTable=[[NSMutableArray alloc] init];
  37. NSMutableArray *arrForTable1=[[NSMutableArray alloc] init];
  38. for (NSDictionary *dict in arrMarkets)
  39. {
  40. NSString *strS1=nil;
  41. strS1= [NSString stringWithFormat:@"%@",[dict valueForKey:@"Description"] ];
  42. [arrForTable addObject:strS1];
  43. }
  44. NSLog(@"%@----------------- ",[arrForTable description]);
  45. for (NSDictionary *dict in arrMarkets)
  46. {
  47. NSString *strS2=nil;
  48. strS2= [NSString stringWithFormat:@"%@",[dict valueForKey:@"Name"] ];
  49. [arrForTable1 addObject:strS2];
  50. }
  51. NSLog(@"%@----------------- ",[arrForTable1 description]);
  52.  
  53. NSArray *Arr = [NSArray arrayWithObjects:obj1,obj2,nil];
  54. NSData *data = [NSPropertyListSerialization dataFromPropertyList:Arr format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];
  55.  
  56. [data writeToFile:PlistDataFilePath atomically:YES];
  57.  
  58. NSData *data = [NSData dataWithContentsOfFile:PlistDataFilePath];
  59. NSPropertyListFormat format;
  60. NSArray *array = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListImmutable format:&format errorDescription:nil];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement