I have a Response class contain a value, and I also have a Value class contain data which conform to Mappable protocol.
Now I have a function to handle Response object, but while I try to get the data out from Value object, it show Type "R" does not conform to protocol.
This is my code in playground:
Update
protocol Mappable{
func doSomething()
}
class User: Mappable {
func doSomething() {
}
}
class Book: Mappable {
func doSomething() {
}
}
class Value<T: Mappable>: Mappable{
var data: T?
func doSomething() {
}
}
class Response<T>{
var value: T?
}
func handleResponse< R: Mappable, T:Value<R>>(response:Response<T>, completeHandler: (R?, NSError?)->()){
completeHandler(response.value!.data, nil) //error goes here: Type "R" does not conform to protocol Mappable
}
let response = Response<Value<User>>()
response.value = Value<User>()
response.value?.data = User()
let response2 = Response<Value<Book>>()
response2.value = Value<Book>()
response2.value?.data = Book()
handleResponse(response, completeHandler:{(r,e)in
print(r)
})
handleResponse(response2, completeHandler:{(r,e)in
print(r)
})
Am I doing it right? Or any other way to achieve this. Thanks