Friday, 23 August 2013

Local Database using Plist in ios


 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"plist.plist"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    NSMutableArray *array = [[NSMutableArray alloc] init];
    
    
    if (![fileManager fileExistsAtPath: path])
    {
      
        [array addObject:1];
        [array writeToFile: [documentsDirectory stringByAppendingPathComponent:@"plist.plist"] atomically:YES];
    }
    else
    {
        [array addObjectsFromArray:[NSArray arrayWithContentsOfFile:path]];
        [array addObject:2];
        [array writeToFile: [documentsDirectory stringByAppendingPathComponent:@"plist.plist"] atomically:YES];
    }


    NSLog(@"%@",array);