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
override func viewWillLayoutSubviews() { | |
super.viewWillLayoutSubviews() | |
contentViewHeight.constant = view.bounds.height > 504 ? view.bounds.height : 504 | |
} |
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
struct API1 { | |
static let BaseURL = "api.airvisual.com/v2/nearest_city?lat={{LATITUDE}}&lon={{LONGITUDE}}&key={{YOUR_API_KEY}}" | |
static let Key = "your_api_key" | |
} | |
enum API2 { | |
static let BaseURL = "api.airvisual.com/v2/nearest_city?lat={{LATITUDE}}&lon={{LONGITUDE}}&key={{YOUR_API_KEY}}" | |
static let Key = "your_api_key" | |
} |
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 API { | |
enum AirVisual { | |
static let BaseURL = "api.airvisual.com/v2/nearest_city?lat={{LATITUDE}}&lon={{LONGITUDE}}&key={{YOUR_API_KEY}}" | |
static let Key = "you_api_key" | |
} | |
enum PropellerAir { | |
static let BaseURL = "https://open.propellerhealth.com/prod/forecast?latitude={{LATITUDE}}&longitude={{LONGITUDE}}" | |
} | |
} |
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
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func applicationDidFinishLaunching(_ application: UIApplication) { | |
if let navigationController = window?.rootViewController as? UINavigationController, | |
let breatherViewController = navigationController.topViewController as? BreatherViewController { | |
// Property and initialiser injection in one line | |
breatherViewController.dataSource = BreatherDataSource(with: NetworkClient()) | |
} |
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 Foundation | |
extension String { | |
/// Returns the indices of all the numbers in the string. | |
/// | |
/// If a number is directly preceded by a dot/comma, the index of the dot/comma | |
/// will also be returned. | |
/// This accounts for potential numbers with decimal or thousands separators. | |
var indicesOfNumbers: [Int] { | |
var indices = [Int]() |
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 | |
extension UILabel { | |
/// Sets the attributedText property of UILabel with an attributed string | |
/// that displays the characters of the text at the given indices in subscript. | |
func setAttributedTextWithSubscripts(text: String, indicesOfSubscripts: [Int]) { | |
let font = self.font! | |
let subscriptFont = font.withSize(font.pointSize * 0.7) | |
let subscriptOffset = -font.pointSize * 0.3 | |
let attributedString = NSMutableAttributedString(string: text, |
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
struct CityConditions { | |
let city: String | |
let weather: Weather | |
let pollution: Pollution | |
let asthma: Asthma | |
} | |
struct Weather { | |
let timestamp: String // timestamp: ex. "2018-12-04T18:00:00.000Z" (ISO 8601) (Z stands for UTC) | |
let iconCode: String // weather icon code: ex. "10n" |
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
extension CityConditions { | |
static func sampleData() -> CityConditions { | |
let weather = Weather(timestamp: "2019-04-16T11:00:00.000Z", | |
iconCode: "01d", | |
temperature: 5, | |
humidity: 36, | |
pressure: 1015, | |
windSpeed: 9.8, | |
windDirection: 300) | |
let pollution = Pollution(timestamp: "2019-04-16T08:00:00.000Z", |
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
// MARK: - Properties | |
private let data = CityConditions.sampleData() | |
// MARK: - Actions | |
@IBAction func aqiStandardSegmentedControlValueChanged(_ sender: UISegmentedControl) { | |
updateAirQualityUI() | |
} |
OlderNewer