Skip to content

Instantly share code, notes, and snippets.

@TerryCK
Created February 27, 2018 12:42
Show Gist options
  • Save TerryCK/d1607985d204d78eee5dfd2a2134bf4a to your computer and use it in GitHub Desktop.
Save TerryCK/d1607985d204d78eee5dfd2a2134bf4a to your computer and use it in GitHub Desktop.
class inheritance enum
import Foundation
class ClassA {
private lazy var cellType = CellType.footer
init(_ x: Int) {
self.cellType = .footer
print("ClassA", self.cellType)
type(of: self.cellType)
}
init() {
print("class init")
}
}
extension ClassA {
enum CellType {
case header, body, footer
}
}
class ClassB: ClassA {
private lazy var cellType = CellType.none
override init() {
super.init()
self.cellType = .none
print("ClassB", self.cellType)
type(of: self.cellType)
}
}
extension ClassB {
private enum CellType {
case header, body, footer, none
init() {
self = .none
}
}
}
// no complie time error and warning :)
let classA = ClassA(1)
let classB = ClassB()
let x = classA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment