我遇到了this problem。
当我将代码调整到该解决方案时,我遇到了另一个问题:我不知道如何/在何处解析泛型类型。
我最终,将我的ViewController的所有类/结构修改为通用(我认为,我甚至可以超越,使其编译)。我觉得哪个不可能走的路?这必须停在某个地方?我的意思是,这只是一个财产的细节。
所以例如:
protocol PhotoData { ... }
// different data for each Provider
class DropboxData: PhotoData { ... }
class PhotoLibraryData: PhotoData { ... }
struct Image<T: PhotoData> {
let image: UIImage
let photoData: T
}
struct ImageConfiguration<T: PhotoData> { // I want to make this Codable to be able store it on disk
let image: Image<T>
...
}
class ViewController<T: PhotoData>: UIViewController {
let config: ImageConfiguration<T>
...
}
我现在完全被这个困住了。任何帮助都非常感谢!