开发者

special characters in Objective-C plist

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


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 is

    [dict objectForKey:@"Leg Width\\n or Height"]

Note that you put a literal backslash in the plist entry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜