plist读写

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"plistdemo" ofType:@"plist"];

    NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];

    NSLog(@"date = %@", data);//直接打印数据。

    

    

    

    //添加一项内容

    [data setObject:@"some content" forKey:@"d_key"];

    [data setObject:@"AAA" forKey:@"c_key"];

    

    //获取应用程序沙盒的Documents目录

    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

    for(int i=0;i<[paths count];i++)

    {

        NSString *plistPath1 = [paths objectAtIndex:i];

        //得到完整的文件名

        NSString *filename=[plistPath1 stringByAppendingPathComponent:@"test.plist"];

        NSLog(@"%@",plistPath);

        //输入写入

        [data writeToFile:filename atomically:YES];

    

        //那怎么证明我的数据写入了呢?读出来看看

        NSMutableDictionary *data1 = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];

        NSLog(@"date = %@", data1);

    }

你可能感兴趣的:(plist)