Objective-c中的NSSet的用法及沙盒机制的用法

来源:互联网 发布:最优化pdf百度云 编辑:程序博客网 时间:2024/06/01 23:39
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);




0 0