gpt4 book ai didi

用于 bool 值的 objective-c getter 装饰器

转载 作者:太空狗 更新时间:2023-10-30 03:42:02 25 4
gpt4 key购买 nike

我正在查看 Objective-C Programming Language documentation更好地了解属性(property)申报和实现。我遇到了这条线,并认为这对我的编码方式可能很重要:

Typically you should specify accessor method names that are key-value coding compliant (see Key-Value Coding Programming Guide)—a common reason for using the getter decorator is to adhere to the isPropertyName convention for Boolean values.

到目前为止,我只是简单地使用了这个:

@property (nonatomic, assign) BOOL aBooleanProperty;

但我一直觉得这可能不太对。

我不明白文档中的最后一部分(突出显示)。这如何暗示我应该提供一个 getter 装饰器,这对我有什么作用?

最佳答案

这意味着您可以为 getter 使用自定义名称,例如

@property (nonatomic, assign, getter=isValue) bool 值;

因此,要获得它,您可以像 [someObject isValue] 而不是 [someObject value] 那样调用它。例如,Apple 使用 NSButton (NSControl) 的 isEnabled 来做到这一点。

关于用于 bool 值的 objective-c getter 装饰器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8067920/

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