Objective-C plist 中的特殊字符
我以前没有遇到过这个问题,但我想知道是否可以在 Objective-C / Cocoa Touch 中存储带有特殊字符的 KEYS
因为可以用 \n 在 NSString 中强制换行,所以我想在 plist 中存储一些值(它们确实需要成为钥匙)。它只有大约 20 行静态数据(嗯,键,值是保存到文件中的 NSNumbers),我不想使用 sqlite,所以它是我可以保存到的字典或静态数组磁盘。
这是.plist alt text http://www.davidhomes.net/plist.png
所以当我尝试为任何没有特殊字符的键设置一个值都可以。但是尝试设置“腿宽\n或高度”会返回
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFDictionary setObject:forKey:]: attempt to insert nil key'
参数 a NSString = @“腿宽\n或高度”
任何帮助表示感谢
最好的问候 大卫
I had not run into this before but I wanted to know if it's possible to store KEYS with special characters in Objective-C / Cocoa Touch
Since one can force a line break in a NSString with \n I wanted to store some values in a plist (and they do need to be the keys). It's just about 20 lines to static data (well, the keys, the values are NSNumbers that get saved to a file) for which I don't want to use sqlite, so it's either a dictionary or a static array that I can save to disk.
Here is the .plist
alt text http://www.davidhomes.net/plist.png
So when I try to set a value for any key without special characters all is fine. But trying to set for, say, 'Leg Width\n or Height' returns
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFDictionary setObject:forKey:]: attempt to insert nil key'
being the argument a NSString = @"Leg Width\n or Height"
Any help is appreciated
Best regards
david
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
plist 编辑器中的字符串是未转义字符串。因此,我通常更喜欢使用 plist 编辑器将正则表达式保留在 plist 文件中。
因此,对于条目
Leg Width\n 或 Height
,要使用的键是请注意,您在 plist 条目中放置了文字反斜杠。
The string in the plist editor is the unescaped string. So, I often prefer to keep regular expressions in the plist file, using the plist editor.
So, for the entry
Leg Width\n or Height
, the key to be used isNote that you put a literal backslash in the plist entry.