简体   繁体   中英

How do you set an integer in CFPreferencesSetAppValue?

I have some problem to write an integer value to the preferences using this:

CFPreferencesSetAppValue(CFSTR("theKey"), CFSTR("0"),(CFStringRef)theID);

The code above will write into preferences as string, how to instead write it as an integer (and so does boolean)?

Thanks in advance!

For booleans, you use CFBoolean (the two values of which are kCFBooleanTrue and kCFBooleanFalse ). For other numbers, you use CFNumber .

Since your question is tagged for Objective-C, you can use (CFTypeRef)@YES , (CFTypeRef)@NO , and/or (CFTypeRef)@(<expr>) to create the objects.

And, of course, if you're setting preferences for the current app, using NSUserDefaults is more natural.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM