ios - Associated type error: Cannot assign a value of type '[SpecificType]' to a value of type '[NameOfTypeAlias]' -
i trying create generic uitableview implementation can display different types of cells. i'm using associated types specify data source type, cell type, , on. have of working well, having trouble subclassing implementation. i'm showing least amount of code can below point across.
here's high-level architecture:
protocol dgtableviewable { typealias dgtableviewitemtype ... var items: [dgtableviewitemtype] { set } } class dgtableview: uitableview, dgtableviewable { typealias dgtableviewitemtype = user var items: [dgtableviewitemtype] = [] { ... } } class dgpoststableview: dgtableview { typealias dgtableviewitemtype = post } ...
things work great when assign array of user
objects dgtableview
instance. example, works great:
var users: [user] = [...] var usertableview: dgtableview usertableview.items = users
however, when try this:
var posts: [post] = [...] var poststableview: dgpoststableview poststableview.items = posts
i error:
cannot assign value of type '[post]' value of type '[dgtableviewitemtype]'
it seems compiler has trouble determining associated types have things set up. ideas why? suggestions on improving architecture?
you're not inheriting dgtableviewable
in class interface dgpoststableview
:
class dgpoststableview: dgtableview, dgtableviewable { typealias dgtableviewitemtype = post ... }