[英]Swift 3 Generic Type usage
First, I have a protocol: 首先,我有一个协议:
public protocol ContentList {
//...
}
and some struct
s: 和一些
struct
:
public struct Post: ContentList {
//...
}
public struct Essay: ContentList {
//...
}
then I have a subclass of UITableViewController
: 然后我有一个
UITableViewController
的子类:
open class MainTableViewController<T: ContentList>: UITableViewController {
// ...
func getData() -> [T] {
retrun ...
}
}
the UI part of this class, MainTableViewController
, was defined in Main.storyboard
, so I did this: 此类的UI部分
MainTableViewController
是在Main.storyboard
中定义的,所以我这样做了:
let kMainTableViewControllerIdentifier = "MainTableViewController"
let listController = (self.storyboard.instantiateViewController(withIdentifier: kMainTableViewControllerIdentifier) as? MainTableViewController<Post>)!
listController.dataSourceType = .post
and I got some error: 我有一些错误:
Unknown class _TtC5Elias23MainTableViewController in Interface Builder file.
Could not cast value of type 'UITableViewController' (0x1af463db8) to 'Elias.MainTableViewController<Elias.Post>' (0x101907af8).
Could not cast value of type 'UITableViewController' (0x1af463db8) to 'Elias.MainTableViewController<Elias.Post>' (0x101907af8).
I have no ideas about how to solve this so far. 到目前为止,我还不知道如何解决这个问题。 so I need some help.
所以我需要一些帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.