Is it possible to invoke NSDictionary's valueForKeyPath: when a key contains periods?

Posted by Jonukas on Stack Overflow See other posts from Stack Overflow or by Jonukas
Published on 2010-05-14T05:46:14Z Indexed on 2010/05/14 14:44 UTC
Read the original article Hit count: 220

Filed under:
|
|
|

I'm trying to get the value of the repeatInterval key in the com.apple.scheduler plist. I'd like to just use NSDictionary's valueForKeyPath: method like so:

CFPropertyListRef value;
value = CFPreferencesCopyValue(CFSTR("AbsoluteSchedule"),
                               CFSTR("com.apple.scheduler"),
                               kCFPreferencesCurrentUser,
                               kCFPreferencesCurrentHost);
NSNumber *repeatInterval = [(NSDictionary *)value valueForKeyPath:@"com.apple.SoftwareUpdate.SUCheckSchedulerTag.Timer.repeatInterval"];

But the problem with this is that the first key is really "com.apple.SoftwareUpdate", not just "com". I can get around this by getting that first value separately:

NSDictionary *dict = [(NSDictionary *)value valueForKey:@"com.apple.SoftwareUpdate"];
NSNumber *repeatInterval = [dict valueForKeyPath:@"SUCheckSchedulerTag.Timer.repeatInterval"];

I just wanted to know if there is a way to escape periods in a keypath so I can eliminate this extra step.

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about mac