NSDictionary *topic = [spaces objectAtIndex:i];
NSInteger topicid = [topic valueForKey:@"TOPICID"];
Run Code Online (Sandbox Code Playgroud)
当我运行这个并打印出主题时,我得到以下内容:
Printing description of topic:
<CFDictionary 0xdb2a70 [0x30307a00]>{type = mutable, count = 2, capacity = 12, pairs = (
10 : <CFString 0xdb5300 [0x30307a00]>{contents = "TOPICID"} = 29
12 : <CFString 0xdb53a0 [0x30307a00]>{contents = "TOPICNAME"} = <CFString 0xdb5360 [0x30307a00]>{contents = "zzzzzzzz"}
)}
Run Code Online (Sandbox Code Playgroud)
但是,当我查看topicid时,值始终是内存地址.我究竟做错了什么?
我正在开发一个iPhone应用程序.
我使用NSDictionary将城市的名称存储为关键,将人口存储为值.我想用小写搜索键.
我用过这个:
NSDictionary *dict;
[dict objectForKey:[[city stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] lowercaseString]];
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用.
我知道,我可以做一个for,将键转换为小写并与城市进行比较.
还有其他办法吗?也许,使用NSDictionary方法.
更新
NSDictionary从属性列表加载.
谢谢.
如果你有一个带有三个NSDictionarys的NSMutableArray,如下所示:
{
name:steve, age:40;
name:steve, age:23;
name:paul, age:19
}
Run Code Online (Sandbox Code Playgroud)
如何将其转换为只有两个字符串的数组{steve,paul}.换句话说,来自原始NSMutableArray的唯一名称?有没有办法使用块来做到这一点?
cocoa-touch nsdictionary nsmutablearray ios objective-c-blocks
我想NSDictionary
从plist 加载一个,我在内存中有plist字符串,我没有plist文件.NSDictionary dictionaryWithContentsOfFile:
只接受文件名,它不接受文件字符串.如何NSDictionary
使用plist文件加载?
我将JSON值分配给NSDictionary并尝试从字典中检索Key.它用括号返回值!
这是它返回的值 (873),("HST 299")
这是JSON
[{"_id":873,"_code":"HST 299"}]
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
NSDictionary *courseDetail = [responseString JSONValue];
NSLog(@"%@ , %@", [courseDetail valueForKey:@"_id"], [courseDetail valueForKey:@"_code"]);
Run Code Online (Sandbox Code Playgroud) 我有NSArray
一些NSDictionaries
自己也包括一个NSDictionary
.
NSDictionary *dict1 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"cover" forKey:@"type"] forKey:@"image"];
NSDictionary *dict2 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"cover" forKey:@"type"] forKey:@"image"];
NSDictionary *dict3 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"back" forKey:@"type"] forKey:@"image"];
NSDictionary *dict4 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"cover" forKey:@"type"] forKey:@"image"];
NSArray *myArray = [NSArray arrayWithObjects:dict1, dict2, dict3, dict4, nil];
Run Code Online (Sandbox Code Playgroud)
有没有办法过滤myArray
所有图像字典,其中类型是使用NSPredicate fe"覆盖"?
尝试谓词喜欢
predicateWithFormat:@"(SELF.image.type == %@)", @"cover"]
Run Code Online (Sandbox Code Playgroud)
要么
predicateWithFormat:@"(image.type == %@)", @"cover"]
Run Code Online (Sandbox Code Playgroud)
但没有成功.
提前致谢!如果不清楚,请发表评论
所以
NSPredicate *p = [NSPredicate predicateWithFormat:@"image.type == %@", @"cover"];
Run Code Online (Sandbox Code Playgroud)
工作中.但在我的情况下,我想整理尺寸==原始.我做的是
NSPredicate *p = [NSPredicate predicateWithFormat:@"image.size …
Run Code Online (Sandbox Code Playgroud) 我还在学习JSON,并使用SBJSON.我将如何获取NSDictionary并将其转换为类似于此的JSON对象:
{"id":"123","list":"456","done":1,"done_date":1305016383}
Run Code Online (Sandbox Code Playgroud) 我有个问题.
我正在使用XMLReader类来获取a NSDictionary
并且一切正常.但我无法获取productData元素的属性值.
具体来说,我有以下内容NSDictionary
:
{
response = {
products = {
productsData = (
{
alias = "Product 1";
id = 01;
price = "10";
},
{
alias = "Product 2";
id = 02;
price = "20";
},
{
alias = "Product 3";
id = 03;
price = "30";
});
};
};
}
Run Code Online (Sandbox Code Playgroud)
我用这段代码来创建de NSDictionary
:
NSDictionary *dictionary = [XMLReader dictionaryForXMLData:responseData error:&parseError];
Run Code Online (Sandbox Code Playgroud)
和responseData包含:
<application>
<products>
<productData>
<id>01</id>
<price>10</price>
<alias>Product 1</alias>
</productData>
<productData>
<id>02</id>
<price>20</price>
<alias>Product 2</alias>
</productData> …
Run Code Online (Sandbox Code Playgroud) 如何按输入顺序输出字典的值是可能的.
例:
我的意见:
[dicValue0 setObject:@"Start Date & Time" forKey:@"START_DATETIME"];
[dicValue0 setObject:@"Specify End" forKey:@"SPECIFY_END"];
[dicValue0 setObject:@"End Date & Time" forKey:@"END_DATETIME"];
[dicValue0 setObject:@"Open End" forKey:@"END_OPEN"];
Run Code Online (Sandbox Code Playgroud)
输出:
我可以编写一个循环,按输入的顺序对输出进行排序.但是,如果我有超过10000个值,这不是最好的和高效的方式.有什么来自苹果,这有助于我解决这个问题吗?
{
Items = {
Item = {
text = "item 1";
}
Item = {
text = "item 2";
}
Item = {
text = "item 3";
}
}
}
Run Code Online (Sandbox Code Playgroud)
以上是我的NSDictionary的一个例子.请记住下一个代码段.
NSDictionary *dict = {the afore mentioned dictionary is here}
int count = [[[dict objectForKey:@"Items"] allKeys] count]; // Breakpoint here
NSLog(@"%i", count); // Breakpoint here
Run Code Online (Sandbox Code Playgroud)
在我的断点中,我得到以下值 count
count = (int) 128037184
或其他一些随机和大的int)count = (int) 5
我原本预计会有3次int.这是怎么回事?
nsdictionary ×10
objective-c ×8
ios ×5
iphone ×5
json ×2
xcode ×2
cocoa-touch ×1
compare ×1
nsarray ×1
nsinteger ×1
nspredicate ×1
nsstring ×1
xmlreader ×1