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
// Code from NSHipster: https://nshipster.com/xcconfig/ | |
import Foundation | |
enum Configuration { | |
enum Error: Swift.Error { | |
case missingKey, invalidValue | |
} | |
static func value<T>(for key: String) throws -> T where T: LosslessStringConvertible { | |
guard let object = Bundle.main.object(forInfoDictionaryKey:key) else { |
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 UIImage { | |
func resizeImage(targetSize: CGSize) -> UIImage { | |
let size = self.size | |
let widthRatio = targetSize.width / size.width | |
let heightRatio = targetSize.height / size.height | |
let newSize = widthRatio > heightRatio ? CGSize(width: size.width * heightRatio, height: size.height * heightRatio) : CGSize(width: size.width * widthRatio, height: size.height * widthRatio) | |
let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height) | |
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0) |
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
// Created for MyTrips | |
// by Stewart Lynch on 2024-01-01 | |
// | |
// Follow me on Mastodon: @[email protected] | |
// Follow me on Threads: @StewartLynch (https://www.threads.net) | |
// Follow me on X: https://x.com/StewartLynch | |
// Subscribe on YouTube: https://youTube.com/@StewartLynch | |
// Buy me a ko-fi: https://ko-fi.com/StewartLynch | |
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
var placeMarks: [MTPlacemark] { | |
[ | |
MTPlacemark(name: "Louvre Museum", address: "93 Rue de Rivoli, 75001 Paris, France", latitude: 48.861950, longitude: 2.336902), | |
MTPlacemark(name: "Sacré-Coeur Basilica", address: "Parvis du Sacré-Cœur, 75018 Paris, France", latitude: 48.886634, longitude: 2.343048), | |
MTPlacemark(name: "Eiffel Tower", address: "5 Avenue Anatole France, 75007 Paris, France", latitude: 48.858258, longitude: 2.294488), | |
MTPlacemark(name: "Moulin Rouge", address: "82 Boulevard de Clichy, 75018 Paris, France", latitude: 48.884134, longitude: 2.332196), | |
MTPlacemark(name: "Arc de Triomphe", address: "Place Charles de Gaulle, 75017 Paris, France", latitude: 48.873776, longitude: 2.295043), | |
MTPlacemark(name: "Gare Du Nord", address: "Paris, France", latitude: 48.880071, longitude: 2.354977), | |
MTPlacemark(name: "Notre Dame Cathedral", address: "6 Rue du Cloître Notre-Dame, 75004 Paris, France", latitude: 48.852972, longitude: 2.350004), | |
MT |
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
static func distance(meters: Double) -> String { | |
let userLocale = Locale.current | |
let formatter = MeasurementFormatter() | |
var options: MeasurementFormatter.UnitOptions = [] | |
options.insert(.providedUnit) | |
options.insert(.naturalScale) | |
formatter.unitOptions = options | |
let meterValue = Measurement(value: meters, unit: UnitLength.meters) | |
let yardsValue = Measurement(value: meters, unit: UnitLength.yards) | |
return formatter.string(from: userLocale.measurementSystem == .metric ? meterValue : yardsValue) |
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
static var capitalizedFirstLettersOfWeekdays: [String] { | |
let calendar = Calendar.current | |
let weekdays = calendar.shortWeekdaySymbols | |
return weekdays.map { weekday in | |
guard let firstLetter = weekday.first else { return "" } | |
return String(firstLetter).capitalized | |
} | |
} |
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
// | |
// Created for MyWeather | |
// by Stewart Lynch on 2024-02-24 | |
// | |
// Follow me on Mastodon: @[email protected] | |
// Follow me on Threads: @StewartLynch (https://www.threads.net) | |
// Follow me on X: https://x.com/StewartLynch | |
// Follow me on LinkedIn: https://linkedin.com/in/StewartLynch | |
// Subscribe on YouTube: https://youTube.com/@StewartLynch | |
// Buy me a ko-fi: https://ko-fi.com/StewartLynch |
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
// | |
// Created for SwiftData-Camera-Photo | |
// by Stewart Lynch on 2024-03-17 | |
// | |
// Follow me on Mastodon: @[email protected] | |
// Follow me on Threads: @StewartLynch (https://www.threads.net) | |
// Follow me on X: https://x.com/StewartLynch | |
// Follow me on LinkedIn: https://linkedin.com/in/StewartLynch | |
// Subscribe on YouTube: https://youTube.com/@StewartLynch | |
// Buy me a ko-fi: https://ko-fi.com/StewartLynch |
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
// | |
// Created for SwiftData Photo_Camera | |
// by Stewart Lynch on 2024-02-18 | |
// | |
// Follow me on Mastodon: @[email protected] | |
// Follow me on Threads: @StewartLynch (https://www.threads.net) | |
// Follow me on X: https://x.com/StewartLynch | |
// Follow me on LinkedIn: https://linkedin.com/in/StewartLynch | |
// Subscribe on YouTube: https://youTube.com/@StewartLynch | |
// Buy me a ko-fi: https://ko-fi.com/StewartLynch |
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 SwiftUI | |
extension Color { | |
// Credit for this goes to https://swiftandtips.com/adaptive-text-color-in-swiftui-based-on-background | |
// This is a slightly modified version to use Computed properties instead of functions | |
var luminance: Double { | |
// perceived brightness of a color 0...1 | |
// Convert SwiftUI Color to UIColor | |
let uiColor = UIColor(self) | |
// Extract RGB values | |
var red: CGFloat = 0 |