Reason: You can not write respondsToSelector
for the swift-based function. There are 2 reasons.
1) In Objective-c, we do have charValue
property in NSNumber
class along with initWithChar
. Whereas in swift we do not have any such properties in NSNumber
class.
@property (readonly) char charValue;
- (NSNumber *)initWithChar:(char)value NS_DESIGNATED_INITIALIZER;
2) respondsToSelector
only accepts Objective-C functions in argument.
Try with writing responds(to: #selector
on NSNumber
and you will found that it only accepts objective-c function and we don't have any such method in Swift NSNumber
class.
let numb: NSNumber?
numb?.responds(to: #selector(@objc method))
Rather, You can use the swift string conversion of NSNumber, as:
let number: NSNumber?
let numberString = number?.stringValue ?? ""
// Added default variable "" in case of string conversion becomes nil