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 TopAlignedLabeledContentStyle: LabeledContentStyle { | |
// You can design it any way you want. | |
func makeBody(configuration: Configuration) -> some View { | |
HStack(alignment: .top) { | |
configuration.label | |
Spacer() | |
configuration.content | |
.foregroundStyle(.secondary) | |
} | |
} |
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 FirstOnAppearModifier: ViewModifier { | |
@State private var hasPerformedAction = false | |
let action: (() -> Void)? | |
func body(content: Content) -> some View { | |
content | |
.onAppear { | |
if !hasPerformedAction { | |
hasPerformedAction = true | |
action?() |
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
// DATE ___DATE___ | |
// TIME ___TIME___ | |
// YEAR ___YEAR___ | |
// --------------------------------- | |
// DEFAULTTOOLCHAINSWIFTVERSION ___DEFAULTTOOLCHAINSWIFTVERSION___ | |
// RUNNINGMACOSVERSION ___RUNNINGMACOSVERSION___ | |
// --------------------------------- | |
// FILEBASENAME ___FILEBASENAME___ | |
// FILEBASENAMEASIDENTIFIER ___FILEBASENAMEASIDENTIFIER___ | |
// FILENAME ___FILENAME___ |
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 |
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
// | |
// 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 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
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
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
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 |