Use of NSSet
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//NSSet Example which uses its own for loop to print seperating by comma.
NSSet *names=[NSSet setWithObjects:@ "Stefan",@ "Silas",@ "Damon", nil];
NSLog(@ "%@",names);
//To calculate the number of objects in a set.
NSLog(@ "The set has %lu elements",names.count);
//Fast Enumeration
for(id name in names){
NSLog(@ "%@",name);
}
//enumerate objects using Block
[names enumerateObjectsUsingBlock:^(id obj, BOOL *stop){
NSLog(@ "Current item: %@",obj);
if ([obj isEqualToString:@ "Damon"]) {
NSLog(@ "I was looking for Damon and I found him!");
*stop=YES; //stop enumerating item
}
}];
}
return 0;
}
No comments:
Post a Comment