NSLog - 奇怪的行为
我发现最后一个单词用双引号显示。但为什么?
NSDictionary *guide2 = [NSDictionary dictionaryWithObjectsAndKeys:kArr, @"Kate", aArr, @"Ana-Lucia", kArr, @"John", nil];
NSArray *array = [guide2 allKeys];
NSLog(@"%@", [array description]);
输出:
(
John,
Kate,
"Ana-Lucia"
)
I found that last word showed with double quotes. But why?
NSDictionary *guide2 = [NSDictionary dictionaryWithObjectsAndKeys:kArr, @"Kate", aArr, @"Ana-Lucia", kArr, @"John", nil];
NSArray *array = [guide2 allKeys];
NSLog(@"%@", [array description]);
output:
(
John,
Kate,
"Ana-Lucia"
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来是因为
Ana-Lucia
键中的特殊字符-
,所以它显示在双引号内。这可能是因为显示键是单个单词。如果您的密钥仅包含“AnaLucia”等字母
,那么它将显示不带引号的键。如果键包含
字母
以外的任何字符,即使它是下划线(_)
或空格
,该键也会显示在双引号中。It seems that because of the special character
-
in the keyAna-Lucia
, it displays it within double-quotes. May be this is because to show that the key is a single word. If your key contains onlyalphabets
like "AnaLucia", then it will display it without quotes.The key is displayed in double-quotes if it contains any characters other than
alphabets
, even if it is anunderscore(_)
orspace
.因为它不是严格意义上的字母数字和一个单词。尝试 NSArray *array = [NSArray arrayWithObjects:@"abc", @"123", @"$abc", @"abc", @"ab c", nil];,你会只看到前两个没有引用。这只是编写描述代码的人的实现选择。
Because it's not strictly alphanumeric and one word only. Try
NSArray *array = [NSArray arrayWithObjects:@"abc", @"123", @"$abc", @"a-b-c", @"a b c", nil];
, you'll see only the first two are not quoted. It's just an implementation choice from the guy who wrote the description code.