Created
March 8, 2018 09:19
-
-
Save Blightwidow/e9a651b922bba4376eaf778d19fee884 to your computer and use it in GitHub Desktop.
Simple Apple MVC file
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
import UIKit | |
import Foundation | |
class mvcViewController: UIViewController { | |
private var photos: Photos? | |
//MARK: View cycle handling | |
override func viewDidLoad() { | |
label.text = "Something" | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
photos = API.fetchPhotos() | |
} | |
override func viewDidAppear(_ animated: Bool) { | |
populateViewWithNewContent() | |
} | |
// MARK: Routing | |
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
guard let photos = photos else { return } | |
doSomethingWithPhotos() | |
} | |
// MARK: Actions | |
@IBOutlet private weak var photoButton: UIButton! | |
@IBAction func pressedPhotoButton(_ sender: Any) { | |
API.addPhoto() | |
disableButton(photoButton) | |
} | |
//MARK: UI Handling | |
private func disableButton(_ button: UIButton) { | |
button.isEnabled = false | |
} | |
@IBOutlet private weak var label: UILabel! | |
private func populateViewWithNewContent() { | |
guard let photos = photos else { return } | |
label.text = "Something" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment