swift - Xcode 9 RespondsToSelector Issue -
nsobject 'responds' method seems broken on latest version of xcode 9 beta 4, swift version 4.0.
below example code tested on xcode 8 (works fine), on xcode 9 method 'responds' returns false situations.
any appreciated.
public class worker : nsobject { public func work() { } public func eat(_ food: anyobject) { } public func sleep(_ hours: int,_ minutes: int) { } } let worker = worker() let canwork = worker.responds(to: selector(("work"))) // true let caneat = worker.responds(to: selector(("eat:"))) // true let cansleep = worker.responds(to: selector(("sleep:minutes:"))) // true let canquit = worker.responds(to: selector(("quit"))) // false
example source : https://stackoverflow.com/a/24168825
there's nothing wrong responds
method. due se-0160 implemented in swift 4, these methods no longer automatically exposed objective-c.
if add @objc
start of each method signature (that want expose objective-c), find responds
returns true
.
public class worker : nsobject { @objc public func work() { } @objc public func eat(_ food: anyobject) { } @objc public func sleep(_ hours: int,_ minutes: int) { } }
alternatively, can add @objmembers
class expose all of methods objective-c.
@objmembers public class worker : nsobject { public func work() { } public func eat(_ food: anyobject) { } public func sleep(_ hours: int,_ minutes: int) { } }
your third selector
syntax wrong. should "sleep::"
because minutes
label not used due preceding _
.
Comments
Post a Comment