[swift-users] Generic type for a generic type?

Jon Shier jon at jonshier.com
Tue Sep 20 16:51:35 CDT 2016


Swifters:
	I’m running into a type inference problem when attempting to pass a generic type which is generic to a generic type to a function which expects a generic type. I’ll explain:

I have a function:
func add<Observer: ProcedureObserver>(observer: Observer) where Observer.Procedure == Procedure

Which I’m sending a parameter of type:

struct BlockObserver<T: ProcedureProcotol>: ProcedureObserver

Which has been provided a type through this function:

func networkProcedureProgressViewObserver<T: URLRequestRoutable, U: Decodable>() -> BlockObserver<NetworkProcedure<T, U>> where U == U.DecodedType

However, calling add(observer: networkProcedureProgressViewObserver()) results in the error: Generic parameter ‘Observer’ could not be inferred. I’ve tried everything I can think of to help the inference but nothing works. Am I correct in thinking this is a limitation of the current generics system not being able to propagate the type information from NetworkProcedure<T, U> to BlockObserver<NetworkProcedure<T, U>> to the function?



Jon


More information about the swift-users mailing list