swift - Cannot convert return expression type to return type with closure? -
hello have func pagination messages.
class func listmessages() -> (int, int, ([chatitemprotocol]) -> void) { let service = messageservice() func list(count: int, offset: int, comp:([chatitemprotocol]) -> void) { let params : [string : anyobject] = ["offset" : offset, "limit" : count] service.listmessagesforroom(params) { (messages) in comp(messages.map({$0})) } } return list }
and have error :
cannot convert return expression of type '(int, offset: int, comp: ([chatitemprotocol]) -> void) -> ()' return type '(int, int, ([chatitemprotocol]) -> void)' (aka '(int, int, array<chatitemprotocol> -> ())')
listmessages(...)
expects following tuple return type
(int, int, ([chatitemprotocol]) -> void)
the function list(...)
, on other hand, uses above argument implicitly contain void
(/empty tuple type ()
) return type. i.e., full signature list(...)
is
(int, int, ([chatitemprotocol]) -> void) -> ()
leading type mis-match when attempt return list
return value of listmessages(...)
.
without knowing purpose of code, difficult give concrete advice, fix above modifying return type of listmessages(...)
include ()
return type, in matching signature of list(...)
class func listmessages() -> ((int, int, ([chatitemprotocol]) -> void) -> ())
Comments
Post a Comment