iOS: plist 인 스 턴 스

8004 단어 plist
 1 //

 2 //  main.m

 3 //  OSXDemo0601_plist

 4 //

 5 //  Created by yao_yu on 14-6-3.

 6 //  Copyright (c) 2014  yao_yu. All rights reserved.

 7 //

 8 

 9 #import <Foundation/Foundation.h>

10 

11 BOOL isfile(NSString *path)

12 {

13     NSFileManager *fileManager = [NSFileManager defaultManager];

14     BOOL isdir = NO;

15     if ([fileManager fileExistsAtPath:path isDirectory: &isdir]) {

16         return isdir == NO;

17     }

18     return NO;

19 }

20 

21 BOOL isdir(NSString *path)

22 {

23     NSFileManager *fileManager = [NSFileManager defaultManager];

24     BOOL isdir = NO;

25     if ([fileManager fileExistsAtPath:path isDirectory: &isdir]) {

26         return isdir == YES;

27     }

28     return NO;

29 }

30 

31 int main(int argc, const char * argv[])

32 {

33 

34     @autoreleasepool {

35         //      

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

37         NSString *documentDir = [paths objectAtIndex:0];

38         

39         //  (  )       

40         NSString *testDir = [[documentDir stringByAppendingPathComponent:@"YY"] stringByAppendingPathComponent:@"Data"];

41         NSFileManager *fileMan = [NSFileManager defaultManager];

42         if (!isdir(testDir))

43             [fileMan createDirectoryAtPath:testDir withIntermediateDirectories:YES attributes:nil error:nil];

44         

45         //  plist  ,      

46         NSString * plistfile = [testDir stringByAppendingPathComponent:@"my.plist"];

47         if (!isfile(plistfile))

48         {

49             NSMutableDictionary *a = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@1,@"A", @2, @"B", nil];

50             [a writeToFile:plistfile atomically:YES];

51         }

52         

53         //  plist  ,     

54         NSMutableDictionary *plist = [NSMutableDictionary dictionaryWithContentsOfFile:plistfile];

55         [plist setObject:@"       " forKey:@"  "];

56         NSLog(@"%@", plist);

57     }

58     return 0;

59 }

좋은 웹페이지 즐겨찾기