gpt4 book ai didi

objective-c - 是否可以调用 NSDictionary 的 valueForKeyPath : when a key contains periods?

转载 作者:太空狗 更新时间:2023-10-30 03:55:05 24 4
gpt4 key购买 nike

我正在尝试获取 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: 方法。它只是调用 NSObject 实现,这是问题的根源。

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

关于objective-c - 是否可以调用 NSDictionary 的 valueForKeyPath : when a key contains periods?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2832066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com