NSArray与NSDictionary的writeToFile分析

测试代码如下:

int main(int argc, char *argv[]) {
    
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	NSArray* animals = [NSArray arrayWithObjects:@"dog",@"cat",nil];
	NSArray* operations = [NSArray arrayWithObjects:@"windows",@"Mac OS X",nil];
	NSArray* books = [NSArray arrayWithObjects:@"C++",@"C",nil];
	NSString * arraypath = @"/Volumes/VMware Shared Folders/VMShare/array.txt";
	[animals writeToFile:arraypath atomically:YES];
  NSDictionary* Dict = [NSDictionary dictionaryWithObjectsAndKeys:animals,@"animal",operations,@"operation system",books,@"programming",nil];
	NSString * dictpath = @"/Volumes/VMware Shared Folders/VMShare/dict.txt";
	[Dict writeToFile:dictpath atomically:YES]; 
	[pool release];
    return 0;
}

array.txt文件的内容

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <string>dog</string>
    <string>cat</string>
</array>
</plist>


dict.txt文件的内容

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>animal</key>
    <array>
        <string>dog</string>
        <string>cat</string>
    </array>
    <key>operation system</key>
    <array>
        <string>windows</string>
        <string>Mac OS X</string>
    </array>
    <key>programming</key>
    <array>
        <string>C++</string>
        <string>C</string>
    </array>
</dict>
</plist>


可见生成的是plist文件,<plist></plist>的第一个标志指定了类型。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值