Consider a base UIViewController class...
class Rooms: UIViewController {
class func instantiate()->Rooms {
}
static func make()->Rooms {
You can do something like this.
class RoomBase: RoomProtocol {
// things common to every room go here
required init() {}
}
You can put in
RoomBase
all the stuff you want the other rooms to inherit.
Next you put the make()
method into a protocol extension.
protocol RoomProtocol: class {
init()
}
extension RoomProtocol where Self: RoomBase {
static func make() -> Self {
let room = Self()
// set up
return room
}
}
Now you can write
class Dining: RoomBase {}
class Bath: RoomBase { }
And this code will work
let dining: Dining = Dining.make()
let bath: Bath = Bath.make()