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
| extension UIImageView { | |
| static func scaledImageWithName(_ name: String, sizeValue: CGFloat) -> UIImageView { | |
| let widthAndHeight = UIFontMetrics.default.scaledValue(for: sizeValue) | |
| let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: widthAndHeight, height: widthAndHeight)) | |
| imageView.image = UIImage(named: name) | |
| return imageView | |
| } | |
| } |
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
| // Enable dragging from the image view (see ViewController+Drag.swift). | |
| let dragInteraction = UIDragInteraction(delegate: self) | |
| dragInteraction.isEnabled = true // this must be enabled for apps targeting iPhone | |
| imageView.addInteraction(dragInteraction) |
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
| class ListNode<T> { | |
| var data: T | |
| var next: ListNode? | |
| init(_ data: T) { | |
| self.data = data | |
| } | |
| // nodes are inserted at the end of the list |
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
| import AudioToolbox.AudioServices | |
| func vibrate() { | |
| AudioServicesPlaySystemSoundWithCompletion(kSystemSoundID_Vibrate) { | |
| // do what you'd like now that the sound has completed playing | |
| } | |
| } |
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
| public enum OnboardingState: Int { | |
| case notStarted | |
| case addLocations | |
| case addStops | |
| case preferences | |
| case finished | |
| func storyboardIdentifier() -> String { | |
| switch self { |
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
| var foodStuffs = [Food]() { | |
| didSet { | |
| // because we perform this operation on the main thread, it is safe | |
| OperationQueue.main.addOperation { // this will not crash | |
| self.tableView.reloadData() | |
| } | |
| } | |
| } |
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
| class FoodTableViewController: UIViewController { | |
| var foodStuffs = [Food]() { | |
| didSet { | |
| // looks good, right? | |
| self.tableView.reloadData() // this will crash :( :( | |
| } | |
| } | |
| func update() { | |
| Updater.doSomethingInBackground { foodResults in |
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
| // | |
| // WeatherController.swift | |
| // Commute | |
| // | |
| // Created by Stephen Francis on 2/17/17. | |
| // Copyright © 2017 Stephen Francis. All rights reserved. | |
| // | |
| import CoreLocation |
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
| // override this in your UIViewController subclass, dictates status bar state for the view controller | |
| override var prefersStatusBarHidden: Bool { | |
| return true | |
| } |
NewerOlder