カスタムクラスを返すメソッドをオーバーライドする方法はありますか?このメソッドをオーバーライドするときメソッドをカスタムクラスの戻り値の型でオーバーライドできません
class CustomClass {
var name = "myName"
}
class Parent: UIViewController {
override func viewDidLoad() {
methodWithNoReturn()
print(methodWithStringAsReturn())
methodWithCustomClassAsReturn()
}
}
extension Parent {
func methodWithNoReturn() { }
func methodWithStringAsReturn() -> String { return "Parent methodWithReturn" }
func methodWithCustomClassAsReturn() -> CustomClass {
return CustomClass()
}
}
class Child: Parent {
override func methodWithNoReturn() {
print("Can override")
}
override func methodWithStringAsReturn() -> String {
print("Cannot override")
return "Child methodWithReturn"
}
override func methodWithCustomClassAsReturn() -> CustomClass {
return CustomClass()
}
}
エラーは、次のとおりです:
私は戻り値の型としてカスタムクラスを任意のメソッドをオーバーライドしようとすると、Xcodeはエラー以下は私のコードです私をスローします
FUNC methodWithCustomClassAsReturn() - > CustomClass
エラーメッセージで:
拡張子からの宣言はまだ
同様の問題:http://stackoverflow.com/questions/27109006/can-you-override-between-extensions-in-swift-or-not-compiler-seems-confused。 –