Мой родительский класс ниже:
Код: Выделить всё
class A: UIViewController {
func parentalGate() {
let appearance = SCLAlertView.SCLAppearance(
kTitleFont: UIFont(name: "Futura", size: 20)!,
kTextFont: UIFont(name: "Futura", size: 14)!,
kButtonFont: UIFont(name: "Futura", size: 14)!,
showCloseButton: false
)
let alert = SCLAlertView(appearance: appearance)
let alert2 = SCLAlertView(appearance: appearance)
if (UserDefaults.standard.object(forKey: "language") as? String == "english") {
let txt = alert.addTextField("Enter third letter")
alert.addButton("Done") {
if ((txt.text == "P") || (txt.text == "p")) {
self.parentalGatefunctions()
} else {
alert2.addButton("Close", target: SCLAlertView(), selector: #selector(SCLAlertView.hideView))
alert2.showError("Incorrect letter entered", subTitle: "Try again")
}
}
alert.addButton("Close", target: SCLAlertView(), selector: #selector(SCLAlertView.hideView))
alert.showWarning("We need to be sure that You are an adult", subTitle: "Enter the third letter of word: HAPPY")
}
}
func parentalGatefunctions(){
// Parental gate functions are overriten in classes where they are used for
}
}
Код: Выделить всё
class B: A {
@IBAction func unlockAllCategoriesBtnPressed(_ sender: Any) {
A().parentalGate()
}
override func parentalGatefunctions() {
print ("Do something in class B")
}
}
Код: Выделить всё
class C: A {
@IBAction func unlockAllCategoriesBtnPressed(_ sender: Any) {
A().parentalGate()
}
override func parentalGatefunctions() {
print ("Do something in class C")
}
}
Я делаю что-то не так? Я просто хочу избежать повторяющегося кода на своих занятиях.
Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/538 ... ing-called
Мобильная версия