详解Cocoa Touch读写Plist项目开发代码

移动开发 iOS
本文介绍的是Cocoa Touch读写Plist项目开发代码,主要是基于代码来实现Cocoa Touch读写Plist的内容,来看详细代码。

Cocoa Touch读写Plist项目开发代码是本文要介绍的内容,内容不多,本文基于代码实现Cocoa Touch读写Plist,不多说,直接来看代码。

  1. - (void) getTopData {  
  2.  
  3.    NSString *documentDirectory = [self getDocumentDirectory];  
  4.    NSString *fileName = @"top2.plist";  
  5.    NSString *finalPath = [documentDirectory stringByAppendingPathComponent: fileName];  
  6.  
  7.    NSMutableDictionary *topRoot = [[NSMutableDictionary alloc] initWithContentsOfFile: finalPath];  
  8.    NSLog(@"%d",[topRoot count]);  
  9. }  
  10.  
  11. - (void) setTopData {  
  12.  
  13.    NSFileManager *fileManager = [NSFileManager defaultManager];  
  14.    NSString *documentDirectory = [self getDocumentDirectory];  
  15.    NSString *fileName = @"top2.plist";  
  16.    NSString *finalPath = [documentDirectory stringByAppendingPathComponent: fileName];  
  17.  
  18.    if (![[NSFileManager defaultManager] fileExistsAtPath: finalPath]) {  
  19.      [fileManager changeCurrentDirectoryPath: [documentDirectory stringByExpandingTildeInPath]];  
  20.  
  21.      NSString *topPath = [[NSBundle mainBundle] pathForResource: @"top" ofType: @"plist"];  
  22.      NSData *topRoot = [NSDictionary dictionaryWithContentsOfFile: topPath];  
  23.  
  24.      [fileManager createFileAtPath:fileName contents: topRoot attributes:nil];  
  25.  
  26.    }else {  
  27.      NSLog(@"file is here!");  
  28.      NSData *topRoot = [[NSMutableDictionary alloc] initWithContentsOfFile: finalPath];  
  29.      [topRoot setValue: @"oo" forKey: [NSString stringWithFormat: @"key%d",arc4random()%1000]];  
  30.      [topRoot writeToFile: finalPath atomically: NO];  
  31.      [fileManager createFileAtPath:fileName contents: topRoot attributes:nil];  
  32.      [topRoot release];  
  33.    }  
  34. }  
  35.  
  36. - (NSString *)getDocumentDirectory {  
  37.    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);  
  38.    return [paths objectAtIndex: 0];  

小结:详解Cocoa Touch读写Plist项目开发代码的内容介绍完了,希望通过本文的学习能对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-07-08 18:03:30

Cocoa Touch 网络

2011-06-15 16:11:51

UIKitCocoa TouchiOS

2011-08-11 15:46:55

CocoaCocoa Touch框架

2011-05-11 10:28:03

2011-07-08 11:13:42

Cocoa Touch XCode

2011-08-03 10:24:22

Cocoa Touch 静态库

2011-07-18 15:08:34

2011-08-05 17:54:33

Cocoa Touch 多语言

2011-07-08 10:49:59

Cocoa Touch 静态库

2011-05-31 15:41:00

Cocoa TouchCocoaiOS

2011-07-20 14:41:53

Cocoa Zip 框架

2011-08-10 18:47:18

Cocoa字符串

2021-03-26 08:20:51

SpringBoot读写分离开发

2023-07-07 08:36:45

配置注解jar

2011-06-27 15:39:51

Cocoa Touch

2011-06-27 16:00:34

视频教程Cocoa TouchiOS应用

2011-08-15 14:47:28

Cocoa嵌入资源文件

2011-07-26 15:29:36

Cocoa 模式

2011-08-02 13:58:18

Cocoa 框架 Mac OS

2011-07-28 16:52:34

Cocoa 框架 Mac Os
点赞
收藏

51CTO技术栈公众号