5

我试图在 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"];

我只是想知道是否有办法在 keypath 中转义句点,这样我就可以消除这个额外的步骤。

4

1 回答 1

1

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

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

于 2010-05-14T15:29:00.103 回答