[swift-users] TWISt-shout Newsletter 2017-06-05

2017-06-04 Thread Kenny Leung via swift-users
Hi All. Here is your TWISt-shout Newsletter for the week of 2017-05-29 to 2017-06-04 https://github.com/pepperdog/TWISt-shout/blob/master/2017/TWISt-shout-2017-06-05.md Enjoy! -Kenny

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Nate Birkholz via swift-users
That works great and is very elegant. Nice work. On Sun, Jun 4, 2017 at 6:34 AM, Geordie J wrote: > In fact, this would be even better (avoids unnecessary implicitly > unwrapped optionals): > > class ClosureGestureRecognizer { > fileprivate var recognizer:

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Charles Srstka via swift-users
Here’s what I’d try. (disclaimer: written in Mail, may contain errors, yadda yadda yadda) public class BlockTapGestureRecognizer: UITapGestureRecognizer { private class Target: NSObject { private let closure: (UITapGestureRecognizer) -> () init(closure: @escaping

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Nate Birkholz via swift-users
Technically it does work(!), but I am hesitant to use it in what amounts to sample code for my current job search, haha. On Sun, Jun 4, 2017 at 4:55 AM, Zhao Xin wrote: > Will this work? > > class TapGestureRecognizer: UITapGestureRecognizer { > > var onTap: (() -> Void)?

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Geordie J via swift-users
In fact, this would be even better (avoids unnecessary implicitly unwrapped optionals): class ClosureGestureRecognizer { fileprivate var recognizer: GestureRecognizer private var onAction: ((GestureRecognizer) -> Void) init(onAction: @escaping ((GestureRecognizer) -> Void)) {

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Geordie J via swift-users
To get around the issue of using self on init, but also that of multiple recogniser types, try this: class ClosureGestureRecognizer { // These are initially nil and set on init to their desired values. // This gets around the issue of using self in init. // `private` means they can't

Re: [swift-users] Optional binding with non-optional expression

2017-06-04 Thread Zhao Xin via swift-users
Then I knew it. if let a: A = A() { // this is a warning as it treats like always true print("something") // this line always runs } For if let a = A() { // show an error as the compiler thinks you are missing something. } For me, the first example, explicitly given the type of `a`, so

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Zhao Xin via swift-users
Will this work? class TapGestureRecognizer: UITapGestureRecognizer { var onTap: (() -> Void)? init(onTap: (() -> Void)?) { self.onTap = onTap super.init(target: nil, action: nil) *self.removeTarget(nil, action: nil)* self.addTarget(self, action:

Re: [swift-users] Optional binding with non-optional expression

2017-06-04 Thread Martin R via swift-users
I don’t think that explains it (or perhaps I did not understand your response correctly). Here is the same issue with a custom type (which does not have a failable initializer): struct A { } if let a = A() { } // error: initializer for conditional binding must have Optional type, not

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Nate Birkholz via swift-users
Also, note that I tried the following: class BlockTapGestureRecognizer: UIGestureRecognizer { var onTap: (() -> Void)? init(onTap: (() -> Void)?) { self.onTap = onTap super.init(target: nil, action: nil) self.addTarget(self, action: #selector(internalTapHandler))

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Nate Birkholz via swift-users
Ah, I didn't read the rest of the thread. As Zhao Xin notes, you cannot call super.init(target: self, action: #selector()), and you cannot call super.init() in a subclass init or convenience init, it *has* to be the designated init method init(target:action:). That's too bad, closure-based gesture

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Nate Birkholz via swift-users
I briefly considered something like this but didn't explore it. Elegant. Sent from my iPhone, please excuse brevity and errors > On Jun 3, 2017, at 9:38 PM, Geordie Jay wrote: > > I am dealing with a variant of this on Android right now. I have just > subclassed e.g.