ios 学习笔记 3

        NSLog(@"Hello, World!");
NSDictionary *myDic=[[NSDictionary alloc]initWithObjectsAndKeys:@"张三",@"name",@"李四",@"name", nil];

NSUInteger count = [myDic count];
NSLog(@"词典的数量为: %lu",count);

NSEnumerator * myEnumerator = [myDic keyEnumerator];


for (NSObject *object in myEnumerator) {
NSLog(@"遍历KEY的值: %@",object);
}

myEnumerator = [[myDic allValues] objectEnumerator];
NSString *value;
while((value = [myEnumerator nextObject]))
{
NSLog(@"遍历的值: %@",value);
}

//通过KEY找到value
NSObject *myObject = [myDic objectForKey:@"name"];

if (myObject != nil) {
NSLog(@"通过KEY找到的value是: %@",myObject);
}

NSMutableDictionary *mydic2 = [NSMutableDictionary dictionaryWithCapacity:10];
[mydic2 setObject:@"Alex Hu" forKey:@"name"];
[mydic2 setObject:@"1388888888" forKey:@"mobile number"];

for (NSObject *object in [mydic2 objectEnumerator]) {
NSLog(@"遍历的值: %@",object);
}

NSSet *mySet=[NSSet setWithObjects:@"A",@"B",@"C",@"D",[NSNumber numberWithInteger:123], nil];
count=[mySet count];
NSLog(@"count= %lu",count);

myEnumerator=[mySet objectEnumerator];
for (NSObject *object in myEnumerator) {
NSLog(@"myEnumerator value=%@",object);
if ([object isEqualTo:@"A"]) {
NSLog(@"找到A了");
}
if ([object isEqual:@"B"]) {
NSLog(@"找到B");
}
}

NSArray *mySetArr=[mySet allObjects];
for (NSUInteger i=0; i<[mySetArr count];i++) {
NSLog(@"%lu =>%@",i,[mySetArr objectAtIndex:i]);
}

if ([mySet containsObject:@"D"]) {
NSLog(@"集合中包含 D这个对象");
}
posted @ 2012-01-21 23:22  alex hu  阅读(356)  评论(0编辑  收藏  举报