I'm trying to create a universal error handler for my application and to make matters even more complicated I'm using an event bus to pass a task around. I'm trying to do the following:
let apiTask = data.object as! Task // Option 1
let apiTask = data.object as! Task<AnyObject> // Option 2
apiTask!.continueWith { (task) in
if(task.cancelled || task.faulted) {
self.isInError = true
} else {
self.isInError = false
}
}
Option 1 gives a compile time error saying the generic type TResut of Task cannot be inferred.
Option 2 causes a runtime error saying Task<SpecificType> cannot be caster to Task<AnyObject>
I have the same implementation in Java where it seems you don't need to specify the generic type so I appreciate this might be a language limitation rather than a library one. TResult could be potentially any type so I can't specify it in the method above. Is there any way to work around this?
I'm trying to create a universal error handler for my application and to make matters even more complicated I'm using an event bus to pass a task around. I'm trying to do the following:
Option 1 gives a compile time error saying the generic type TResut of Task cannot be inferred.
Option 2 causes a runtime error saying
Task<SpecificType> cannot be caster to Task<AnyObject>I have the same implementation in Java where it seems you don't need to specify the generic type so I appreciate this might be a language limitation rather than a library one.
TResultcould be potentially any type so I can't specify it in the method above. Is there any way to work around this?