-
Notifications
You must be signed in to change notification settings - Fork 85
Convert getter-like methods into readonly properties #181
Conversation
This improves the Swift bridging
|
||
@implementation PCKMessageCapturer | ||
@implementation PCKMessageCapturer { | ||
NSMutableArray *_sent_messages; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are modernizing, why move this to an ivar?
Looks great, except that I don't understand the introduction of the ivar. does this help somehow, or was it a style choice? If the latter, I would prefer we not do that here. |
@akitchen ah yeah, I was a little surprised that it was necessary as well. The problem is described here a little. Basically the compiler synthesizes the ivar based on the type declared in the (Edit: I'll also mention that I now recall having repeatedly forgotten about this quirk of the compiler, and being a little annoyed each time when I've tried to use this pattern in the past 😬) |
Thanks for the explanation! It would be nice if a test target would fail to
|
Well, it did fail to compile until I removed the property from the class extension and added the explicit ivar instead. The reason it worked previously was that the public interface had a simple method rather than a property. It would be nice to have some tests requiring these to remain property declarations, but I'm not sure how to do that without adding one or more Swift spec files which presents some challenges, in particular with CI and Xcode versions. Do you think it's worth it? |
Convert getter-like methods into readonly properties
Works for me. Thanks @pivotal-rebecca-chin & @briancroom ! |
This improves the Swift bridging. The methods get bridged into Swift as functions, which need to be invoked with
()
which feels un-idomatic when they are intended to effectively be getters.This is especially problematic in cases like
tableRowAction.handler()
which (previously) would return the handler closure, but not actually invoke it, despite appearances.Thanks to @pivotal-rebecca-chin for first making me aware of this issue and tracking down what was going on.