API之NSSet的常见用法

来源:互联网 发布:读懂php wsdl中方法 编辑:程序博客网 时间:2024/05/29 08:33

/*

NSSet *set1 = [[NSSet alloc] initWithObjects:@" ",@"性别不明", @"非地球物种", nil];

NSArray *array = [set1 allObjects];

for (int i = 0; i < [array count]; i++) {

NSLog(@"%@", [array objectAtIndex:i]);

}


//是否包含对象

if ([set1 containsObject:@"name"]) {

NSLog(@"yes");

} else {

NSLog(@"no");

}

NSSet *set2 = [[NSSet alloc] initWithObjects:@"",@"性别不明", @"地球生物", nil];


//判断集合1和集合2是否碰撞

if ([set1 intersectsSet:set2]) {

NSLog(@"yes");

} else {

NSLog(@"no");

}

if ([set1 isEqualToSet:set2]) {

NSLog(@"yes");

} else {

NSLog(@"no");

}


//集合2是否是集合1子集

if ([set1 isSubsetOfSet:set2]) {

NSLog(@"yes");

} else {

NSLog(@"no");

}



*/

NSMutableSet *mSet1= [[NSMutableSetallocinitWithObjects:@"aaa",@"sss", @"ddd", @"dfg",

@"fgfd", nil];

NSMutableSet *mSet2= [[NSMutableSetallocinitWithObjects:@"sss",@"dfg", @"drf", nil];


//数组1减去数组2

// - (void)minusSet:(NSSet *)otherSet;

// [mSet1 minusSet:mSet2];

// NSLog(@"%@", mSet1);


//数组拼接

// - (void)unionSet:(NSSet *)otherSet;

[mSet1 unionSet:mSet2];

NSLog(@"%@", mSet1);

0 0
原创粉丝点击