mvvm - Swift associated types and protocol inheritance -


i'm using swift 2.2 , declared protocol associated type follow:

protocol collectionviewmodeling {     associatedtype celltype     func cellatindexpath(indexpath: nsindexpath) -> celltype } 

now have view model protocol conform above protocol :

enum myitemcell {     case myitemcell1, myitemcell2 } protocol itemslistviewmodeling: collectionviewmodeling {     associatedtype celltype = mycell } 

finally, somewhere else, want declare var conform le protocol itemslistviewmodeling :

var viewmodel: itemslistviewmodeling 

and i'm getting error :

protocol 'itemslistviewmodeling' can used generic constraint because has self or associated type requirements

but can create class implements protocol.

is possible declare var associated typed protocol ? i'm giving final type of associated type in protocol itemslistviewmodeling, don't understand why seeing error compiler.

thanks

see there stackoverflow.com

you can't treat protocols associated types regular protocols , declare them standalone variable types.


Comments