设为首页 加入收藏

TOP

Objective-c 集合对象(二)
2017-10-12 18:17:06 】 浏览:8020
Tags:Objective-c 集合 对象
tersect
"); 34 else 35 NSLog(@"set and set4 no intersect"); 36 37 BOOL isequal = [set isEqualToSet:set2]; 38 if(isequal) 39 NSLog(@"set = set2"); 40 else 41 NSLog(@"set != set2"); 42 43 } 44 return 0; 45 }

 

 

  4)可变集合(NSMutable)

  

 

 

  下面通过一个例子来说可变集合的用法:

  

 1 #import <Foundation/Foundation.h>
 2 
 3 @interface NSString (print)
 4 -(void)print;
 5 -(void)show:(NSString *)str;
 6 @end
 7 
 8 @implementation NSString(print)
 9 -(void)print{
10     NSLog(@"%@",self);
11 }
12 -(void)show:(NSString *)str{
13     NSLog(@"%@ : %@",str,self);
14 }
15 @end
16 
17 int main(int argc,char **argv){
18     @autoreleasepool {
19         NSMutableSet *mset = [NSMutableSet setWithObjects:@"zhangsan",@"lisi",@"wangwu", nil];
20         
21         [mset addObject:@"zhaoliu"];
22         NSLog(@"mset = %@",mset);
23         
24         [mset addObjectsFromArray:@[@"111",@"222",@"333"]];
25         NSLog(@"mset = %@",mset);
26         
27         [mset removeObject:@"111"];
28         NSLog(@"mset = %@",mset);
29         
30         NSSortDescriptor *sortdesr = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];
31         NSArray *sortset = [mset sortedArrayUsingDescriptors:@[sortdesr]];
32         NSLog(@"mset sort = %@",sortset);
33         
34         NSArray *array = [mset allObjects];
35         NSLog(@"array = %@",array);
36         NSSet *set2 = [NSSet setWithArray:array];
37         NSLog(@"set2 = %@",set2);
38         
39         NSString *str = [mset anyObject];
40         NSLog(@"str = %@",str);
41         
42         [mset setSet:set2];
43         NSLog(@"mset = %@",mset);
44         
45         [mset removeAllObjects];
46         NSLog(@"mset = %@",mset);
47     }
48 }

 

  

  

  

  

 

 

      

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇UINavigationController导航控制器 下一篇1014-34-首页15-计算原创微博的fr..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目