Created
January 23, 2017 19:28
-
-
Save staycreativedesign/7ee91aa7e44a4f95fc0cfabe4a9a8a72 to your computer and use it in GitHub Desktop.
First app
This file contains hidden or 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
| // | |
| // FactProvider.swift | |
| // fun facts | |
| // | |
| // | |
| import Foundation | |
| struct FactProvider { | |
| let facts: [String] = ["this is awesome", "woot", "woot woot", "wooting is rough"] | |
| func randomFact() -> String { | |
| let factPosition = arc4random_uniform(UInt32(facts.count)) | |
| return facts[Int(factPosition)] | |
| } | |
| } |
This file contains hidden or 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
| // | |
| // RandomColorGenerator.swift | |
| // fun facts | |
| // | |
| // | |
| import UIKit | |
| func randomColor() -> UIColor { | |
| let red = randomNumber() | |
| let green = randomNumber() | |
| let blue = randomNumber() | |
| let color = UIColor(colorLiteralRed: red/255, green: green/255, blue: blue/255, alpha: 1) | |
| return color | |
| } | |
| func randomNumber() -> Float { | |
| let number = Float(arc4random_uniform(255)) | |
| return number | |
| } |
This file contains hidden or 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
| // | |
| // ViewController.swift | |
| // fun facts | |
| // | |
| // | |
| import UIKit | |
| class ViewController: UIViewController { | |
| @IBOutlet weak var factLbl: UILabel! { | |
| didSet { | |
| factLbl.textColor = UIColor.white | |
| } | |
| } | |
| @IBOutlet weak var factBtn: UIButton! { | |
| didSet { | |
| factBtn.setTitle("Hello", for: .normal) | |
| factBtn.setTitleColor(.white, for: .normal) | |
| } | |
| } | |
| let fact = FactProvider() | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| view.backgroundColor = randomColor() | |
| factLbl.text = "Some interesting facts" | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| // Dispose of any resources that can be recreated. | |
| } | |
| @IBAction func factBtn(_ sender: UIButton) { | |
| factLbl.text = fact.randomFact() | |
| view.backgroundColor = randomColor() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment