Reputation: 8029
When creating a class extension on a foundation class I get a unrecognized selector sent to instance
when using the following:
extension NSURLSessionDataTask: Taskable {
func isRunning() -> Bool {
return state == .Running
}
}
Error:
[__NSCFLocalDataTask isRunning]: unrecognized selector sent to instance 0x7fa93bdc07d0
I am trying to create a common task interface so I am able to use different kinds of classes such as operations and session tasks, is there something I am missing here?
Upvotes: 2
Views: 935
Reputation: 93161
Many of Cocoa classes are "class clusters", meaning you may get a different one from what you asked for. NSCFLocalDataTask
is a private class and looks like it doesn't inherit from NSURLSessionDataTask
. Try moving your extension to NSURLSessionTask
.
Upvotes: 4
Reputation: 52538
Why this might happen: Objective-C BOOL properties starting with "is" may be handled differently. It may be that your func is exported to Objective-C as the "running" method, not as "isRunning".
Upvotes: 0