Objective-c中的NSSet的用法及沙盒机制的用法
2014-03-05 21:43
337 查看
NSSet声明编程接口对象的无序集合
NSArray *arrayy = [NSArray arrayWithObjects:@"one",@"jdjdf",@"jdjjf", nil];
NSSet *set = [[NSSet alloc]initWithObjects:@"one",@"two", nil];
NSSet *set1 = [[NSSet alloc]initWithArray:arrayy];
NSArray *array1 = [set anyObject];
NSLog(@"%@",array1);
NSLog(@"%@",set);
NSArray *array = [set allObjects];
NSLog(@"%@",array);
BOOL isContain = [set containsObject:set1];
NSLog(@"%d",isContain);
BOOL isIntersect = [set intersectsSet:set1];
NSLog(@"%d",isIntersect);
BOOL isEqual = [set isEqualToSet:set1];
NSLog(@"%d",isEqual);
NSSet *set2 = [NSSet setWithObjects:@"ooo",@"pppp", nil];
NSLog(@"%@",set2);
NSMutableSet *set3 = [NSMutableSet setWithSet:set2];
NSMutableSet *set4 = [NSMutableSet setWithObjects:@"xxxx",@"pppp",@"ooo",@"llll", nil];
[set3 minusSet:set4];
[set2 intersectsSet:set4];
[set3 unionSet:set];
沙盒机制
ios应用程序只能对自己创建的文件系统读取文件,这个“独立”“安全”的空间,我们称为沙盒。他一般存放着你的程序文件(可执行文件)、图片、声音、视频、plist、sqlite数据库以及其他文件。
每个应用程序都有自己独立的存储空间(沙盒)。
一般来说应用程序间是不可以相互访问。
每个沙盒含有三个文件。分别是Document、Library、tmp。
Document:一般我们需要持久的数据都放在这个目录。尤其iTunes备份和恢复。
Library:设置程序的默认设置和其他信息状态。
//获取根目录
NSString *homePaths = NSHomeDirectory();
NSLog(@"%@",homePaths);
//获取Documents的目录
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSLog(@"%@",paths);
NSString *docPath = [paths lastObject];
NSLog(@"%@",docPath);
//获取Library中的Cache目录
NSArray *path2 = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *lib_CachePath= [path2 lastObject];
NSLog(@"%@",lib_CachePath);
//获取tmp的目录
NSString *temp = NSTemporaryDirectory();
NSLog(@"%@",temp);
//NSString类路径处理方法
NSString *newPath = @"/Users/lihongmei/Desktop/ppppppp";
NSString * aa = [newPath lastPathComponent];
NSString * bb = [newPath stringByDeletingLastPathComponent];
NSLog(@"%@",aa);
NSLog(@"%@",bb);
NSString *array = [newPath pathExtension];
NSLog(@"%@",array);
NSArray *arrayy = [NSArray arrayWithObjects:@"one",@"jdjdf",@"jdjjf", nil];
NSSet *set = [[NSSet alloc]initWithObjects:@"one",@"two", nil];
NSSet *set1 = [[NSSet alloc]initWithArray:arrayy];
NSArray *array1 = [set anyObject];
NSLog(@"%@",array1);
NSLog(@"%@",set);
NSArray *array = [set allObjects];
NSLog(@"%@",array);
BOOL isContain = [set containsObject:set1];
NSLog(@"%d",isContain);
BOOL isIntersect = [set intersectsSet:set1];
NSLog(@"%d",isIntersect);
BOOL isEqual = [set isEqualToSet:set1];
NSLog(@"%d",isEqual);
NSSet *set2 = [NSSet setWithObjects:@"ooo",@"pppp", nil];
NSLog(@"%@",set2);
NSMutableSet *set3 = [NSMutableSet setWithSet:set2];
NSMutableSet *set4 = [NSMutableSet setWithObjects:@"xxxx",@"pppp",@"ooo",@"llll", nil];
[set3 minusSet:set4];
[set2 intersectsSet:set4];
[set3 unionSet:set];
沙盒机制
ios应用程序只能对自己创建的文件系统读取文件,这个“独立”“安全”的空间,我们称为沙盒。他一般存放着你的程序文件(可执行文件)、图片、声音、视频、plist、sqlite数据库以及其他文件。
每个应用程序都有自己独立的存储空间(沙盒)。
一般来说应用程序间是不可以相互访问。
每个沙盒含有三个文件。分别是Document、Library、tmp。
Document:一般我们需要持久的数据都放在这个目录。尤其iTunes备份和恢复。
Library:设置程序的默认设置和其他信息状态。
//获取根目录
NSString *homePaths = NSHomeDirectory();
NSLog(@"%@",homePaths);
//获取Documents的目录
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSLog(@"%@",paths);
NSString *docPath = [paths lastObject];
NSLog(@"%@",docPath);
//获取Library中的Cache目录
NSArray *path2 = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *lib_CachePath= [path2 lastObject];
NSLog(@"%@",lib_CachePath);
//获取tmp的目录
NSString *temp = NSTemporaryDirectory();
NSLog(@"%@",temp);
//NSString类路径处理方法
NSString *newPath = @"/Users/lihongmei/Desktop/ppppppp";
NSString * aa = [newPath lastPathComponent];
NSString * bb = [newPath stringByDeletingLastPathComponent];
NSLog(@"%@",aa);
NSLog(@"%@",bb);
NSString *array = [newPath pathExtension];
NSLog(@"%@",array);
相关文章推荐
- Objective-C:NSSet和NSMutbaleSet的用法
- Objective-C的self.用法的一些总结
- Objective-C中nil与release的区别与用法
- Redis Sentinel 机制与用法(二)
- Objective-C NSString的常用用法
- NSSet、NSMutableSet基本用法
- iOS学习之iOS沙盒(sandbox)机制和文件操作(一) .
- Objective-C语言:关联机制
- cocos2d-x 3.0触摸机制的用法
- Objective-C学习-NSSet(集合),NSMutableSet(可变集合) NSCountSet(计数集合)
- iOS学习之iOS沙盒(sandbox)机制和文件操作(一)
- iOS学习之iOS沙盒(sandbox)机制和文件操作(一)
- 沙盒机制
- Objective-C 日记② 关于self用法
- IOS沙盒(sandbox)机制和文件操作
- Objective-C内存管理详解——ARC和垃圾回收机制
- Objective-C中nil与release的区别与用法
- Objective-C RunTime机制(1)
- iOS沙盒(sandbox)机制和文件操作
- 记录Objective-C里SEL和Selector的用法