我试图在 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 中转义句点,这样我就可以消除这个额外的步骤。