Bunu yapmaya çalışıyorum ama bazı sorunlarıSwift jenerik ertelendi sorunu
Bu
protocol CustomProtocol {
}
SubCustomProtocol
protocol SubCustomProtocol: CustomProtocol {
}
SubCustomProtocolImplementation
class SubCustomProtocolImplementation: SubCustomProtocol {
}
CustomProtocol
olduğunu alıyorum
Bu CustomClass
class CustomClass<P: CustomProtocol> {
var customProtocol: P?
func doSomething() {
}
}
SubCustomClass
class SubCustomClass<P: SubCustomProtocol>: CustomSubClass {
}
Ve BaseViewController
class BaseViewController<P: CustomProtocol, T: CustomClass<P>>: UIViewController {
var foo: T!
override func viewDidLoad() {
super.viewDidLoad()
foo?.doSomething()
}
}
Benim ViewController ben foo çağrı doğrultusunda
class ViewController<P: SubCustomProtocolImplementation, T: SubCustomClass<P>>: BaseViewController<P,T> {
override func viewDidLoad() {
super.viewDidLoad()
}
}
nedir? .doSomething() it diyor 'T' 'CustomClass < 'P'>' bir alt tipi değil ve ne yaptığımı bilmiyorum yanlış
Ve ViewController bildiriminde o BaseViewController T CustomClass devralan gerektiriyor" diyor
< 'P'> "Umarım bana yardımcı olabilirsin!
Bu hatayı alamıyorum. En azından oyun alanında. Tam bağlamı sağladığınızdan emin misiniz? – iyuna
@Iyuna Üzgün bir şey kaçırıyordum! –
sorusunu düzenledim Görünüşe göre, bir tip parametresi genel bir sınıf tarafından kısıtlanamaz. Bir sınıf veya bir protokol tarafından kısıtlanabilir. – CouchDeveloper