写文件数组与字典
来源:互联网 发布:oracle sql 变量 编辑:程序博客网 时间:2024/05/20 16:42
//
// writeFile.m
//
// Created by Wangjue on 13-9-8.
// Copyright (c) 2013年 Wangjue. All rights reserved.
//
#import "writeFile.h"
@implementation writeFile
- (void)writeDict
{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
for (NSInteger i =0 ; i<20; i++) {
NSString *keyName = [NSString stringWithFormat:@"key-%02d",i];
NSMutableArray *arry = [NSMutableArray array];
NSInteger rnd = arc4random_uniform(10)+5;
for (NSInteger j = 0; j < rnd; j++) {
NSString *text = [NSString stringWithFormat:@"itcast-%d"];
[arry addObject:text];
}
[dict setValue:arry forKey:keyName];
}
NSArray *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *path = [documents[0] stringByAppendingPathComponent:@"dict.plist"];
[dict writeToFile:path atomically:YES];
}
- (void)writeArray
{
// 1.实例化数组
NSMutableArray *array =[NSMutableArray array];
for (NSInteger i = 0; i < 20; i++) {
NSString *text = [NSString stringWithFormat:@"hehe-%d",i];
[array addObject:text];
}
// 2.获取文件路径
NSArray *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
// 3.NSString添加文件路径
NSString *path = [documents[0] stringByAppendingPathComponent:@"array.plist"];
// 4.创建并写入文件
[array writeToFile:path atomically:YES];
}
@end
- 写文件数组与字典
- Javascript 数组与字典
- swift数组与字典
- 写文件 :数组,字典,字符串, NSData 都有同一个 writeToFile 方法写入文件
- Python字典与文件
- swift -入门与 数组 字典
- 数组与字典的应用
- OC数组与字典详解
- 字典与数组的相互包含
- 使用 NSPropertyListSerialization 持久化字典与数组
- 使用 NSPropertyListSerialization 持久化字典与数组
- UITableView 数组与字典结合(省市区)
- Javascript数组与字典用法分析
- oc中数组与字典的总结
- OC 字典与数组 中文输出 NSlog
- Swift第二课 数组与字典
- swift学习笔记之数组与字典
- ios字典与数组转JSon
- 数字图像处理-空间域图像增强(二)(直方图)
- static_cast, dynamic_cast, const_cast探讨
- JSON与Go
- 第二十周周报
- 浅析iOS中Push通知的使用
- 写文件数组与字典
- 用javascript修改html元素的class
- OpenSSL 中 RSA 加密解密实现源码分析
- Android数据库更新并保留原来数据的实现
- ubuntu安装jdk7,eclipse,cross tool(arm)
- divide an array by the size
- iOS开发进阶精华贴索引
- 移动硬盘等外设安装KUbuntu
- 沈海高速货车自燃(图)