A: "objectForKey:" is an NSDictionary method. An NSDictionary is a collection class similar to an NSArray, except instead of using indexes, it uses keys to differentiate between items. A key is an arbitrary string you provide. No 2 objects can have the same key (just as no 2 objects in an NSArray can have the same index).
"valueForKey: is KVC method. It works with ANY class. "valueForKey" allows you to access an instance variable using a string. So for instance, if I have an Account class with an instance variable accountNumber, I can do the following:
Using KVC, I can also do it like this:
Those are equivalent sets of statements.
I know you're thinking: wow, but sarcastically. KVC doesn't look all that useful. In fact, it looks "wordy". But when you want to change things at runtime, you can do lots of cool things that are much more difficult in other languages (but this is beyond the scope of your question).
If you want to learn more about KVC, there are many tutorials if you Google especially at Scott Stevenson's blog.
Hope that helps.
相关推荐
NULL 博文链接:https://justsee.iteye.com/blog/2252988
- (id)objectForKey:(id)aKey expectedClass:(Class)expectedClass withTransformerClass:(Class)transformerClass; - (id)objectForKey:(id)aKey withTransformerBlock:(JMOTransformerBlock)transformerBlock...
NSLog(@"json1.a:%@",[data1 objectForKey"a"]); NSLog(@"json1.b:%@",[data1 objectForKey"b"]); [json1 release]; // 如果json有嵌套,即value里有array、object,如果再使用objectFromJSONString,程序可能会...
int aa=[[defs1 objectForKey:@"ishelp"] intValue]; if (aa!=5) { [defs1 setObject:@"5" forKey:@"ishelp"]; [self helpScroll]; [defs1 synchronize]; } 引导页在程序中只会显示一次 */ ...
UIImage * image=[info objectForKey:UIImagePickerControllerEditedImage]; [self performSelector:@selector(selectPic:) withObject:imageafterDelay:0.1]; } -(void)selectPic:(UIImage*)image { NSLog(@...
NSString * controllerNameStr = [smallDic objectForKey:@"controllerName"]; //将字符串转化为类名 Class controllerNameClass = NSClassFromString(controllerNameStr); //创建类对应的视图控制器对象 ...
value = [dictionary objectForKey:@"id"];if ([value isKindOfClass:[NSNumber class]]) { model.identifier = [value unsignedLongLongValue];}value = [dictionary objectForKey:@"title"];if ([value ...
return ((CCString*)strings->objectForKey(key))->m_sString; } static std::string getImagePathsByKey(std::string key) { if(imagePaths == NULL) { std::string path = CCFileUtils::sharedFileUtils()->...
HBHashButton 要安装,请将源代码下载到您的项目中。 在您的项目中添加行 #import "UIButton+HBHashButton.h" UIButtons 现在可以像 NSMutableDictionary ...NSLog(@"Value is: %@",[button objectForKey:@"value"])
plist文件是标准的xml文件 A).写入plist文件:(Dictionary/Array) NSMutableDictionary* dict = [ [ NSMutableDictionary alloc ] ...NSString* object = [ dict objectForKey:@"RestartSpringBoard" ];
self.codeView.code = [dict objectForKey:@"code"]; }]; }]; [self.codeView didChangeVerificationCode:^(NSString *code) { NSLog(@"self.codeView code:%@",code); }]; //开始生成code [self.codeView ...
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; [self saveImage:image withName:@"currentImage.png"]; NSString *fullPath = [[NSHomeDirectory() ...
[cache objectForKey: @" foo " ]; // nil [cache setObject @" bar " forKey: @" foo " ]; [cache objectForKey: @" foo " ]; // @"bar" 而且,只要您的密钥符合NSCopying协议,您就可以使用类似 NSDictionary 的...
item.itemTitle = [dict objectForKey:@"placeName"]; item.itemDesc = [dict objectForKey:@"placeDesc"]; item.itemImage = [dict objectForKey:@"placeImage"]; [array addObject:item]; } ...
- ( void )objectForKey:( NSString *)key usingBlock:( void (^)( id object))block; - ( void )setObject:( id )object forKey:( NSString *)key; 有关方法的完整列表,请参见 。 添加到您的项目 只需将SYCache.h...
【原创】转帖请注明来源,谢谢 -tag 1- 测试无内存泄露 1 创建数据对象() NSMutableDictionary *map = [... node.nodeValue = [map objectForKey:key]; [self addChildNode:node]; } } @end
// returns immediately[[PINCache sharedCache] objectForKey:@"image" block:^(PINCache *cache, NSString *key, id object) { UIImage *image = (UIImage *)object; NSLog(@"image scale: %f", image.scale);...
// returns immediately[[PINCache sharedCache] objectForKey:@"image" block:^(PINCache *cache, NSString *key, id object) { UIImage *image = (UIImage *)object; NSLog(@"image scale: %f", image.scale);...
Info.plist用于向iOS提供关于app,bundle或者framework的一些重要信息。它指定了比如一个应用应该怎样启动,它如何被本地化,应用的名称,要显示的图标,...NSString *localVersion = [infoDic objectForKey:@”CFBundl
[queryItemArray addObject:[NSURLQueryItem queryItemWithName:@"version" value:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]]]; [urlComponents setQueryItems:...