This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProfileViewController: UIViewController { | |
// MARK: - Properties | |
var mode: Mode = .viewing { | |
didSet { | |
updateEditingModeUI() | |
} | |
} | |
// MARK: - Outlets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func updateEditingModeUI() { | |
nameField.isUserInteractionEnabled = mode.textfieldsEditable | |
ageField.isUserInteractionEnabled = mode.textfieldsEditable | |
primaryButton.setTitle ... | |
secondaryButton.setTitle ... | |
secondaryButton.isHidden ... | |
} | |
func handleSave() { | |
// perform appropriate validations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Mode { | |
/// ... | |
var primaryText: String { | |
switch self { | |
case .editing: return "Save" | |
case .viewing: return "Edit" | |
case .creating: return "Create" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Mode { | |
case viewing | |
case editing | |
case creating | |
var textfieldsEditable: Bool { | |
switch self { | |
case .editing, .creating: return true | |
case .viewing: return false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func secondaryButtonPressed(sender: UIButton) { | |
switch mode { | |
case .viewing: break // This button will be hidden | |
case .creating: backToSignup() // I'm not going to define the implementation for these | |
case .editing: revertTextfields() // functions here but you can imagine that it | |
// what they both would do | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func primaryButtonPressed(sender: UIButton) { | |
switch mode { | |
case .viewing: mode = .editing | |
case .editing, .creating: handleSave() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProfileViewController: UIViewController { | |
// Mark: - Properties | |
var mode: Mode = .viewing { | |
didSet { | |
updateEditingModeUI() | |
} | |
} | |
// ... (hidden) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProfileViewController: UIViewController { | |
// Mark Outlets | |
@IBAOutlet weak var nameField: UITextField! | |
@IBAOutlet weak var ageField: UITextField! | |
@IBAOutlet weak var primaryButton: UIButton! | |
@IBAOutlet weak var secondaryButton: UIButton! | |
// Mark Button Actions | |
@IBAction func primaryButtonPressed(sender: UIButton) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Mode { | |
case viewing | |
case editing | |
case creating | |
var textfieldsEditable: Bool { | |
switch self { | |
case .editing, .creating: return true | |
case .viewing: return false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Mode { | |
case viewing | |
case editing | |
case creating | |
} |
NewerOlder