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: GestureRecognizer
> private var
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 (UIT
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)?
>
> init(onTap:
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)) {
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
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: #selec
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))
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
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. UITapGestureRecognizer to
That's why I thanked for for the amendment. As I said, typing code blindly
on the phone, mistakes are inevitable. Thanks for clearing it up.
On Sun 4. Jun 2017 at 15:04, Zhao Xin wrote:
> I was not talking about the formatting. I am talking about the
> implementation.
>
> You can't use `self` bef
I was not talking about the formatting. I am talking about the
implementation.
You can't use `self` before you call `super.init` as you did now. If
changing your implementation to called `super.init` and then call `self`
in `super.init` again. You would have called `super.init` twice. I don't
kno
Thanks for the amendment, and sorry for the (lack of) formatting. I
painstakingly typed that on my phone with manually-spaced indenting, which
the Inbox app unhelpfully removed entirely when I pressed send. Pasting
into Xcode should do the trick though..
Geordie
On Sun 4. Jun 2017 at 14:49, Zhao X
You should change to another way. Using `self` in `super.init` is not
allowed.
Zhaoxin
On Sun, Jun 4, 2017 at 12:38 PM, Geordie Jay wrote:
> I am dealing with a variant of this on Android right now. I have just
> subclassed e.g. UITapGestureRecognizer to perform the 2nd variant above and
> exte
I am dealing with a variant of this on Android right now. I have just
subclassed e.g. UITapGestureRecognizer to perform the 2nd variant above and
externally accept a closure as its argument. I'm writing this on my phone
so forgive any syntax errors or accidental omissions:
class TapGestureRecogniz
Thanks, the second had occurred to me, but felt a little too much like in
practice it would make the code harder to understand.
On Fri, Jun 2, 2017 at 9:58 PM, Zhao Xin wrote:
> I found two workarounds.
>
> 1.
>
> protocol Foo: class {
>
> func bar()
>
> }
>
>
> class Base:Foo {
>
> @obj
I found two workarounds.
1.
protocol Foo: class {
func bar()
}
class Base:Foo {
@objc func bar() {
print("bar")
}
}
class Baz: Base {
override init() {
super.init()
let tapRecognizer = UITapGestureRecognizer(target: self, action:
#selector(bar)
protocol Foo: class {
func bar()
}
extension Foo {
func bar() {
print("bar")
}
}
class Baz: Foo {
init() {
let tapRecognizer = UITapGestureRecognizer(target: self, action:
#selector(bar))
}
}
the #selector tells me: "Argument of '#selector' refers to instance
17 matches
Mail list logo