//
// main.m
// OSXDemo0601_plist
//
// Created by yao_yu on 14-6-3.
// Copyright (c) 2014年 yao_yu. All rights reserved.
//
#import <Foundation/Foundation.h>
BOOL isfile(NSString *path)
{
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isdir = NO;
if ([fileManager fileExistsAtPath:path isDirectory: &isdir]) {
return isdir == NO;
}
return NO;
}
BOOL isdir(NSString *path)
{
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isdir = NO;
if ([fileManager fileExistsAtPath:path isDirectory: &isdir]) {
return isdir == YES;
}
return NO;
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
//得到文档目录
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [paths objectAtIndex:0];
//得到(创建)自定义数据目录
NSString *testDir = [[documentDir stringByAppendingPathComponent:@"YY"] stringByAppendingPathComponent:@"Data"];
NSFileManager *fileMan = [NSFileManager defaultManager];
if (!isdir(testDir))
[fileMan createDirectoryAtPath:testDir withIntermediateDirectories:YES attributes:nil error:nil];
//创建plist文件, 序列化字典
NSString * plistfile = [testDir stringByAppendingPathComponent:@"my.plist"];
if (!isfile(plistfile))
{
NSMutableDictionary *a = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@1,@"A", @2, @"B", nil];
[a writeToFile:plistfile atomically:YES];
}
//读取plist文件, 反序列化
NSMutableDictionary *plist = [NSMutableDictionary dictionaryWithContentsOfFile:plistfile];
[plist setObject:@"中华人民共和国" forKey:@"国家"];
NSLog(@"%@", plist);
}
return 0;
}
iOS: plist应用实例
最新推荐文章于 2014-07-27 23:08:35 发布