NSMutableDictionary
网上:
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:@"John" forKey:@"Firstname"];
[dict setObject:@"Doe" forKey:@"Lastname"];
[dict setObject:@"info@objectgraph.com" forKey:@"Email"];
NSLog(@"%@===aaa", dict);
NSArray *keys = [dict allKeys];
// values in foreach loop
for (NSString *key in keys) {
NSLog(@"%@ is %@",key, [dict objectForKey:key]);
}
[dict removeObjectForKey:@"Email"];
自己:
NSMutableDictionary *d=[[NSMutableDictionary alloc]init];
[d setObject:@"zhang" forKey:@"z"];
[d setObject:@"ming" forKey:@"m"];
[d setObject:@"wei" forKey:@"w"];
NSLog(@"%@",[d objectForKey:@"w"]);
NSArray *keys1=[d allKeys];
for (NSString *key1 in keys1) {
NSLog(@"%@ is %@",key1,[d objectForKey:key1]);
}
[d removeObjectForKey:@"z"];
for (NSString *key1 in keys1) {
NSLog(@"%@ is %@",key1,[d objectForKey:key1]);
}
控制台:
2012-08-22 20:14:13.996 Student[3066:707] {
Email = "info@objectgraph.com";
Firstname = John;
Lastname = Doe;
}===aaa
2012-08-22 20:14:14.090 Student[3066:707] Email is info@objectgraph.com
2012-08-22 20:14:14.125 Student[3066:707] Firstname is John
2012-08-22 20:14:14.126 Student[3066:707] Lastname is Doe
2012-08-22 20:14:14.127 Student[3066:707] wei
2012-08-22 20:14:14.128 Student[3066:707] z is zhang
2012-08-22 20:14:14.129 Student[3066:707] m is ming
2012-08-22 20:14:14.129 Student[3066:707] w is wei
2012-08-22 20:14:14.130 Student[3066:707] z is (null)
2012-08-22 20:14:14.130 Student[3066:707] m is ming
2012-08-22 20:14:14.131 Student[3066:707] w is wei
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:@"John" forKey:@"Firstname"];
[dict setObject:@"Doe" forKey:@"Lastname"];
[dict setObject:@"info@objectgraph.com" forKey:@"Email"];
NSLog(@"%@===aaa", dict);
NSArray *keys = [dict allKeys];
// values in foreach loop
for (NSString *key in keys) {
NSLog(@"%@ is %@",key, [dict objectForKey:key]);
}
[dict removeObjectForKey:@"Email"];
自己:
NSMutableDictionary *d=[[NSMutableDictionary alloc]init];
[d setObject:@"zhang" forKey:@"z"];
[d setObject:@"ming" forKey:@"m"];
[d setObject:@"wei" forKey:@"w"];
NSLog(@"%@",[d objectForKey:@"w"]);
NSArray *keys1=[d allKeys];
for (NSString *key1 in keys1) {
NSLog(@"%@ is %@",key1,[d objectForKey:key1]);
}
[d removeObjectForKey:@"z"];
for (NSString *key1 in keys1) {
NSLog(@"%@ is %@",key1,[d objectForKey:key1]);
}
控制台:
2012-08-22 20:14:13.996 Student[3066:707] {
Email = "info@objectgraph.com";
Firstname = John;
Lastname = Doe;
}===aaa
2012-08-22 20:14:14.090 Student[3066:707] Email is info@objectgraph.com
2012-08-22 20:14:14.125 Student[3066:707] Firstname is John
2012-08-22 20:14:14.126 Student[3066:707] Lastname is Doe
2012-08-22 20:14:14.127 Student[3066:707] wei
2012-08-22 20:14:14.128 Student[3066:707] z is zhang
2012-08-22 20:14:14.129 Student[3066:707] m is ming
2012-08-22 20:14:14.129 Student[3066:707] w is wei
2012-08-22 20:14:14.130 Student[3066:707] z is (null)
2012-08-22 20:14:14.130 Student[3066:707] m is ming
2012-08-22 20:14:14.131 Student[3066:707] w is wei
相关推荐
在iOS和Mac开发中,`NSMutableDictionary`是Foundation框架中的一个核心类,它是`NSDictionary`的子类,提供了可变的键值对存储功能。在标准的`NSMutableDictionary`中,键值对的插入顺序并不是保留的,也就是说当你...
1.字典使用Key-Value的形式储存数据,是关键字及其定义(描述)的集合 2.字典中的对象储存没有顺序,使用key来表示每个对象,key唯一,Value值可相同 3.字典里Value值在前,key在后 Cocoa中的实现字典的集合...
NSDictionary NSMutableDictionary 增强 Import pod 'NSDictionary-Enhance', '~> 1.0.0' Usage #import "NSDictionary+VDEnhance.h" [NSDictionary vd_dictionaryWithDictionary:originDic mergeWithDictionary:dic...
FFSafeKit安全地使用NSArray,NSMutableArray,NSDictionary,NSMutableDictionary,NSMutableString。 功能安全访问NSArray安全访问NSDictionary安全访问并执行更改FFSafeKit安全地使用NSArray,NSMutableArray,...
此类是NSMutableDictionary类集群的扩展,因此您期望从 Foundation Collections 获得的所有方法(主要在NSMutableDictionary公共抽象接口中)也可以在此类上调用,除了初始化方法。 该类支持,除其他外, NSCopying...
- **知识点解释:** 集合分为可变集合(如`NSMutableArray`, `NSMutableSet`, `NSMutableDictionary`)和不可变集合(如`NSArray`, `NSSet`, `NSDictionary`)。可变集合允许在其生命周期内添加或移除元素,而不可变...
Objective-C-如何创建和使用NSDictionary和NSMutableDictionary-Latest-2017-Hindi- 视频:-Yogesh Patel在Objective-C中使用NSDictionary和NSMutableDictionary的介绍。 在本频道中,我将在多部视频中讲授大多数...
NSMutableDictionary* dict = [ [ NSMutableDictionary alloc ] initWithContentsOfFile:@"/Sample.plist" ]; [ dict setObject:@"Yes" forKey:@"RestartSpringBoard" ]; [ dict writeToFile:@"/Sample.plist" ...
这些类包括NSArray、NSSet、NSEnumerator和NSDictionary,以及它们的可变版本NSMutableArray、NSMutableSet和NSMutableDictionary。这些类提供了各种操作来处理对象的集合,如添加、删除、查找等。以下是关于这些类...
在Objective-C中,词典对象通常通过NSDictionary类及其可变子类NSMutableDictionary来实现。NSDictionary用于存储键值对形式的数据集合,其中每个键对应一个对象(值)。本知识点总结将详细介绍Objective-C中...
- (void)finishTransaction:(NSMutableDictionary *)transactionInfo; @end @interface PaymentAdapter : NSObject @property (nonatomic, strong) ThirdPartyPayment *thirdPartyPayment; @end @...
3 返回NSMutableDictionary或者NSMutableArray,键值封装。 示例见最后的注释。 XML封装类待续。。。 转载请注明来源,谢谢 ====== XmlResolve.h #import <Foundation/Foundation.h> @interface ...
这里,我们创建一个名为`ZHBlockSingleCategroy`的分类(Category),为`NSMutableDictionary`添加一个Block类型的属性。在Objective-C中,由于Block不能直接作为分类的实例变量,我们需要使用运行时特性来实现这一...
NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary]; selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12]; selectedAttrs[NSForegroundColorAttributeName] = [UIColor ...
NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { NSString *keyString = nil; NSString...
- 初始化:`NSMutableDictionary *mutableDict = [[NSMutableDictionary alloc] init];` - 设置值:`[mutableDict setObject:@"NewValue" forKey:@"key"];` - 删除键值对:`[mutableDict removeObjectForKey:@...
NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; [params setObject:@"taobao.taobaoke.items.get" forKey:@"method"]; [params setObject:@"num_iid,title,pic_url,price,score" forKey:@...
NSMutableDictionary *usernamepasswordKVPairs = [NSMutableDictionary dictionary]; [usernamepasswordKVPairs setObject:txtfldUsername.text forKey:KEY_USERNAME]; [usernamepasswordKVPairs setObject:...
NSMutableDictionary *map = [[NSMutableDictionary alloc]init]; [map setObject:@"a" forKey:@"author"]; [map setObject:@"b" forKey:@"title"]; [map setObject:@"c" forKey:@"content"]; 或者 ...
> NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; > [parameters setObject:mainPort forKey:@"port"]; > > // start the secondary threads > // loop starts at 1 because the main thread...