我试图将NSDictionary的内容放入NSString进行测试,但不知道如何实现这一点.可能吗?如果是这样,怎么会做这样的事情?
我这样做的原因是,我需要检查NSDicitonary的内容,而不需要在我的设备上运行调试器.因为我必须从ios的多任务栏删除正在运行的应用程序,所以我可以看到我保存到字典中的值是否仍然可用.
有没有办法将选择器存储在一个NSDictionary,而不是存储为NSString?
我不确定我是否正在使用字典或数据对象或两者都不正确.我试图习惯切换到快速但我有点麻烦.
var dictionaryExample : [String:AnyObject] =
["user":"UserName",
"pass":"password",
"token":"0123456789",
"image":0] // image should be either NSData or empty
let dataExample : NSData = dictionaryExample as NSData
Run Code Online (Sandbox Code Playgroud)
我需要NSDictionary编码到一个NSData对象以及获取该NSData对象并将其解码为NSDictionary.
非常感谢任何帮助,谢谢.
我怎么能转换的NSArray一种NSDictionary,通过阵列的对象的一个int领域作为重点NSDictionary?
我可以NSDictionary根据钥匙进行排序吗?
NSDictionary* fileAttributes =
[[NSFileManager defaultManager] attributesOfItemAtPath:filename
error:nil]
Run Code Online (Sandbox Code Playgroud)
从文件属性键,您可以获得日期,大小等.但是如何获得持续时间?
我有一个现有的NSDictionary,它具有:
{
"charts_count" = 2;
"created_at" = "2010-04-12T16:37:32Z";
exchange = NASDAQ;
"followers_count" = 259;
id = 8404;
industry = "<null>";
"messages_count" = 1436;
ric = "GRPN.O";
sector = "<null>";
symbol = GRPN;
title = Groupon;
"updated_at" = "2011-09-05T04:17:56Z";
}
Run Code Online (Sandbox Code Playgroud)
我如何获取这些内容并将其放入新的NSMutableDictionary中?
iphone cocoa-touch objective-c nsdictionary nsmutabledictionary
这可能是一个非常基本的问题,但我想知道为什么我不能将nil指定为NSDictionary值?我在我的代码中有很多地方.如果[q objectForKey:@"text"]是零,那么App正在崩溃.
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:2];
[dict setObject:[q objectForKey:@"text"] forKey:@"text"];
Run Code Online (Sandbox Code Playgroud)
在将其分配给字典之前,我必须检查无处不在的nil.这是唯一正确的做法吗?我错过了一些明显的东西吗
if([q objectForKey:@"text"] != nil)
[dict setObject:[q objectForKey:@"text"] forKey:@"text"];
else
[dict setObject:@"" forKey:@"text"];
Run Code Online (Sandbox Code Playgroud) 我有一个NSMutableDictionary整数值,我想获得一个键的数组,按其各自的值升序排序.例如,使用这个字典:
mutableDict = {
"A" = 2,
"B" = 4,
"C" = 3,
"D" = 1,
}
Run Code Online (Sandbox Code Playgroud)
我想最终得到阵列["D", "A", "C", "B"].当然,我真正的字典比四个项目大得多.
现在我知道,当swift编译它只是创建一个NSDictionary,但NSDictionary和Swift词典有不同的语法.有没有办法(通过循环或其他东西)将NSDictionary转换为相同类型的快速字典<key, value>?
要么
有没有办法将其转换为Swift字典而不是NSDictionary?
let jsonDict = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &error) as NSDictionary
Run Code Online (Sandbox Code Playgroud) nsdictionary ×10
ios ×4
iphone ×4
objective-c ×4
cocoa-touch ×3
swift ×2
audio ×1
cocoa ×1
dictionary ×1
duration ×1
file ×1
key ×1
nsarray ×1
nsdata ×1
nsstring ×1
null ×1
selector ×1
sorting ×1