Objective c 是否可以调用NSDictionary';s valueForKeyPath:当键包含句点时?

Objective c 是否可以调用NSDictionary';s valueForKeyPath:当键包含句点时?,objective-c,cocoa,macos,foundation,Objective C,Cocoa,Macos,Foundation,我正在尝试获取com.apple.scheduler plist中repeatInterval键的值。我只想使用NSDictionary的valueForKeyPath:方法,如下所示: CFPropertyListRef value; value = CFPreferencesCopyValue(CFSTR("AbsoluteSchedule"), CFSTR("com.apple.scheduler"),

我正在尝试获取com.apple.scheduler plist中repeatInterval键的值。我只想使用NSDictionary的valueForKeyPath:方法,如下所示:

CFPropertyListRef value;
value = CFPreferencesCopyValue(CFSTR("AbsoluteSchedule"),
                               CFSTR("com.apple.scheduler"),
                               kCFPreferencesCurrentUser,
                               kCFPreferencesCurrentHost);
NSNumber *repeatInterval = [(NSDictionary *)value valueForKeyPath:@"com.apple.SoftwareUpdate.SUCheckSchedulerTag.Timer.repeatInterval"];
但问题是,第一个键实际上是“com.apple.SoftwareUpdate”,而不仅仅是“com”。我可以通过分别获取第一个值来解决这个问题:

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

我只是想知道是否有一种方法可以在键路径中转义句点,这样我就可以消除这个额外的步骤。

NSDictionary没有valueforKeyPath:method。它只调用NSObject实现,这是问题的根源


也许你可以在NSDictionary的一个类别中用你自己的转义字符重新实现它。

我不认为我会经常遇到这个问题来证明为它编写一个类别是有道理的,所以我现在只需要多写一行代码。谢谢你的澄清。