Here's a snippet of swift test code, why this does not working? How to make it working?
import UIKit
class SwiftTestController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
test()
}
func test() {
let resourceViews: Array<any ResourceView> = []
// type-checking error in this line.
let resources = resourceViews.map { $0.resource }
}
}
protocol ResourceComponent {
}
// fine
protocol ResourceView: ResourceComponent {
associatedtype R: Resource
var resource: R { get set }
}
// does not working
//protocol ResourceView: UIView, ResourceComponent {
// associatedtype R: Resource
// var resource: R { get set }
//}
// does not working
//protocol ResourceView: UIView {
// associatedtype R: Resource
// var resource: R { get set }
//}
protocol Resource {}
Below is a image for detail error message!
let ResourceView
does not inherit(constraint to) UIView
works fine.
I've submitted a issue.