[swift-evolution] [Idea] Make Boolean @objc properties reflect better into Objective-C
Jeff Kelley
slaunchaman at gmail.com
Tue Feb 23 15:02:26 CST 2016
+1. This definitely matches my real-world use of boolean properties across
both languages.
Jeff Kelley
SlaunchaMan at gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan> |
jeffkelley.org
On Tue, Feb 23, 2016 at 4:00 PM, Douglas Gregor via swift-evolution <
swift-evolution at swift.org> wrote:
> Hi all,
>
> The Swift API guidelines state that Boolean properties should reflect
> assertions about the receiver, so in Swift one would expect:
>
> class Foo {
> var isEnabled: Bool // good
> }
>
> rather than
>
> class Foo {
> var enabled: Bool // not Swifty
> }
>
> When the property is @objc, e.g.,
>
> class Foo : NSObject {
> @objc var isEnabled: Bool
> }
>
> The resulting Objective-C property doesn’t follow the Cocoa guidelines
> for Objective-C
> <https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#//apple_ref/doc/uid/20001284-BAJGIIJE>
> :
>
> @property (readwrite,nonatomic) BOOL isEnabled;
>
> because those guidelines state that properties do not use the “is” prefix.
>
> My proposal is to strip the “is” prefix from the Objective-C name, but
> leave it off the getter, e.g.,
>
> @property (readwrite,nonatomic,getter=isEnabled) BOOL enabled;
>
> The change would have no effect on the Swift name; it will only affect the
> Objective-C property name and setter name.
>
> Thoughts?
>
> - Doug
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160223/3f3f4790/attachment.html>
More information about the swift-evolution
mailing list