ios - In Swift, cannot subclass generic: class Foo<T> : T {} -


i have 1 class, a, sub-classed uicollectionviewcontroller. class, b, sub-classed uiviewcontroller; b contains uicollectionview. there enough common logic between , b factor out logic common extension. thinking create generic, foo<t>, relevant extensions, , encode , b follows:

class : foo<uicollectionviewcontroller> 

and

class b: foo<uiviewcontroller> 

with foo<t> this:

class foo<t> : t { ... } 

this fails because generic parameter t evidently cannot referenced super-class.

to around issue, tried solution protocols , protocol extensions, approach did not work: @objc functions (eg, handlers uicollectionviewdatasource) not defined within protocol extensions.

it seems overkill "normalize" , b being same type of controller. common "extensions" want add , b handlers uicollectionviewdatasource, uicollectionviewdelegate, uiimagepickercontrollerdelegate.

is there way enable kind of extended logic generics?

there enough common logic between , b factor out logic common extension

i don't see how generic going here; seems misunderstanding of generic is.

it appears goal inject same implementation of e.g. uicollectionviewdatasource methods multiple view controller classes automatically. there no way that.

your view controller classes can have uicollectionviewdatasource method calls common functionality, can inject through protocol extension or whatever; classes must still implement each uicollectionviewdatasource method explicitly , individually.

that's because that's way objective-c ever going see implementation , call in automatic way need collection view functionality operate.

remember, cocoa written in objective-c. knows nothing of swift features such protocol extensions , generics, , can't see them.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -