Skip to content

Casting to Task without specifying generic type #36

Description

@adrianhr91

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions