-1

I have this code: for the simulator to write a NSmutableArray in a plist

 NSString *path = [[NSBundle mainBundle] pathForResource: @"Array" ofType:@"plist"];

if([Array writeToFile:path atomically: YES]){
    NSLog(@"write succesful");}
else {
    NSLog(@"write failed");
}

but how I can check if really the file plist is empty?

cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241

2 Answers2

0

Although this code works in the iOS Simulator, you will not be able to write into your app bundle on iOS devices.

Alexsander Akers
  • 15,967
  • 12
  • 58
  • 83
  • You would probably want to write to the documents folder: `[[[NSFileManager defaultManager] URLsForDirectory: NSDocumentDirectory inDomains: NSUserDomainMask] lastObject]` – Alexsander Akers May 20 '11 at 14:51
0

Write the file.

[[NSFileManger defaultManager] createFileAtPath:path contents:plistData withAttributes:attributesDictionary];

Check the file for the array.

NSDictionary *infoDictionary = [NSDictionary dictionaryWithContentsOfFile:path];
if ([infoDictionary count] == expectedIntegerValue) {
  NSLog(@"Success");
  if ([infoDictionary objectForKey:@"ARRAY_KEY"]) {
    NSLog(@"Found the array!");
  } else {
    NSLog(@"No Array Found.");
  }
} else {
  NSLog(@"Fail");
}

if you just want to know if there are any keys [infoDictionary count] > 0.

Kyle
  • 1,662
  • 2
  • 21
  • 38