저는 신속하게 제네릭을 잘못 이해하고 있습니다. 비 명목 형 X는 명시 적 초기화를 지원하지 않습니다.
나는이 샘플 놀이터를 만들어import UIKit
public protocol MainControllerToModelInterface : class {
func addGoal()
init()
}
public protocol MainViewControllerInterface : class {
associatedtype MODELVIEW
var modelView: MODELVIEW? {get set}
init(modelView: MODELVIEW)
}
public class MainViewController<M> : UIViewController, MainViewControllerInterface where M : MainControllerToModelInterface {
public weak var modelView: M?
required public init(modelView: M) {
self.modelView = modelView
super.init(nibName: String(describing: MainViewController.self), bundle: Bundle.main)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
public class Other<C, M> : NSObject where C : MainViewControllerInterface, C : UIViewController, M : MainControllerToModelInterface, C.MODELVIEW == M {
var c : C?
override init() {
let m = M()
self.c = C(modelView: m)
super.init()
}
}
라인 self.c = C(modelView: m)
내가 나이가 Xcode의 버전이 오류가
cannot invoke initializer for type '%type' with an argument list of type '...' expected an argument list of type '...'
을 의미 볼 this other stack overflow 질문에서 나에게이 오류 non-nominal type 'C' does not support explicit initialization
을 제공합니다 하지만 위의 놀이터에서 컴파일러 mi는 무엇입니까? ssing?
나는 swift4/xcode9에 있습니다.
업데이트
의 제안을 Use C.init(modelView: m) rather than C(modelView: m)
오류 변화를 다음과 후 : @보다
No 'C.Type.init' candidates produce the expected contextual result type '_?'
VINI - 응용 프로그램이 작동하는지 확인하기 위해있는 UIViewController을 제거하기 위해 제안했다. UIViewController가있을 때 나는 왜 컴파일러가 행복하지 않은지 아직 이해하지 못한다. C가 그 유효한 init 메소드를 가지고 있다는 것을 아는 것으로 충분하지 않습니까?
self.c = C.init(modelView: m)
감사합니다, 나는'얻기보다 'C.Type.init'후보가 예상 문맥을 생산하는 이유가의 ViewController로
C
취급하고후
init(modelView: M)
그게 전부 같은의 ViewController에는init
없다 결과 유형 '_?' ' –내 주요 프로젝트에서이 문제가 실제로 해결되었습니다. –