See NSUserDefaults file content

2019-02-18 20:50发布

Is there any way I can see the content of NSUserDefaults? I'm able to open the plist file using "pico" from the terminal, but it shows weird characters, I can't actually see the content file content. Is there any way I can open the file in Xcode?

Basically, I want to be able to see and edit the content of NSUserDefaults without the need of doing so programmatically, I'd like to do so from the Terminal or from Xcode. Cheers!

4条回答
SAY GOODBYE
2楼-- · 2019-02-18 21:09

As of Mac OS X 10.8, directly editing the contents of user defaults files is very likely to fail randomly. You must use either the defaults command, the NSUserDefaults API, or the CFPreferences API.

查看更多
走好不送
3楼-- · 2019-02-18 21:30

I'm able to open the file using "pico" but it shows weird characters.

Because as an optimization (storage space and read/write speed) iOS stores property list files in the binary format. You need to convert it to XML format using

plutil -convert xml1 com.yourapp.bundleid.plist

After this, you'll be able to see a meaningful result when opened in a text editor (such as Pico).

查看更多
forever°为你锁心
4楼-- · 2019-02-18 21:34

You can also open the file in Xcode. Simply double-clicking on it should open it in Xcode.

查看更多
Deceive 欺骗
5楼-- · 2019-02-18 21:35

You can use the defaults command-line tool to easy access the UserDefaults.

defaults read <domain> <key>
defaults write <domain> <key> <value>

You can also delete keys or the whole domain (bundle id) if you need it.

查看更多
登录 后发表回答