Swayer Geroge Swayer Geroge - 1 year ago 87
iOS Question

Swift3.0: Can not call value of non-functional type'((Selector!)->Bool)!'

I have to migrate my swift 2.x code to Swift 3.0. In this case, I found an issue "Can not call value of non-functional type ((Selector!)-> Bool)!".
I googled but not found any good solution which solved my problem.

I have one class, which is written in Objective-C :

@interface AEngineBool : AEngineData
@property BOOL value;

And one another view controller class, I access this using respondToSelector like this

let param: AnyObject = params[0]
if param.responds(#selector(AEngineBool.value)) {
let iType: Bool = param.value
// Something

and getting an error on param.response() point, which I mention above.

If I changed the
if (param.responds(to: #selector(getter: AEngineBool.value))), then I am getting an error Ambiguous use for 'value(forKey:)'.

Answer Source

Ok, it looks like you have 3 problems: 1) are using the wrong signature for responds() 2) value is a getter and it should be labelled as so, and 3) the 'value' property name is ambiguous.

See this:

if param.responds(to: #selector(getter: AEngineBool.value)){
     let iType = param.value // gives error 'value' is ambiguous
     // something?

But if i create another BOOL property on your original class, that has a more unique name:

@interface AEngineBool : NSObject
@property BOOL value;
@property BOOL uniquePropertyName;

Then this is all good:

if param.responds(to: #selector(getter: AEngineBool.uniquePropertyName)){
      let iType = param.uniquePropertyName
      // something?

So i think value is just to general of a word and collides with value(forKey:) and others...

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download