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;
@end
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:)'.
Ok, it looks like you have 3 problems:
responds()
value
is a getter and it should be labelled as so, and 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;
@end
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...
also can't figure out the error given by XCode, but i would code around it. Would this work for your implementation?
let param: AnyObject = params[0]
if param is AEngineBool {
let iType: Bool = param.value
// something?
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.