开发者

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

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 *)v开发者_JS百科alue 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.


NSDictionary doesn't have a valueforKeyPath: method. It just invokes the NSObject implementation which is the root of your problem.

Maybe you could reimplement it in a category on NSDictionary with your own escape characters.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜