Skip to content

Instantly share code, notes, and snippets.

View StewartLynch's full-sized avatar

Stewart Lynch StewartLynch

View GitHub Profile
@StewartLynch
StewartLynch / FiLEHEADER_Macros.txt
Last active May 31, 2024 21:37
Xcode Fileheader Macros
// DATE ___DATE___
// TIME ___TIME___
// YEAR ___YEAR___
// ---------------------------------
// DEFAULTTOOLCHAINSWIFTVERSION ___DEFAULTTOOLCHAINSWIFTVERSION___
// RUNNINGMACOSVERSION ___RUNNINGMACOSVERSION___
// ---------------------------------
// FILEBASENAME ___FILEBASENAME___
// FILEBASENAMEASIDENTIFIER ___FILEBASENAMEASIDENTIFIER___
// FILENAME ___FILENAME___
@StewartLynch
StewartLynch / AdaptiveColorExtension.swift
Created May 20, 2024 21:36
Adaptive Text Color Extension
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
@StewartLynch
StewartLynch / ZoomableScrollView.swift
Created March 17, 2024 23:57
A Zoomable and Scrollable Image View for SwiftUI
//
// Created for SwiftData Photo_Camera
// by Stewart Lynch on 2024-02-18
//
// Follow me on Mastodon: @StewartLynch@iosdev.space
// 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
@StewartLynch
StewartLynch / ImagePicker.swift
Last active March 17, 2024 22:33
A gist for the YouTube tutorial on picking and adding photos from your photos library
//
// Created for SwiftData-Camera-Photo
// by Stewart Lynch on 2024-03-17
//
// Follow me on Mastodon: @StewartLynch@iosdev.space
// 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
//
// Created for MyWeather
// by Stewart Lynch on 2024-02-24
//
// Follow me on Mastodon: @StewartLynch@iosdev.space
// 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
@StewartLynch
StewartLynch / DateString.txt
Last active March 15, 2024 13:11
Two Static functions for getting weekday and month names for the Custom Calendar App
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
}
}
@StewartLynch
StewartLynch / Locale Distance.txt
Last active April 26, 2024 22:35
Uses the correct distance for the Locale you are in
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)
@StewartLynch
StewartLynch / placemarks.txt
Created January 4, 2024 00:59
Sample MKPlacemark Array
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
@StewartLynch
StewartLynch / SampleParisLocations.swift
Last active January 2, 2024 06:02
Sample Paris Locations
// Created for MyTrips
// by Stewart Lynch on 2024-01-01
//
// Follow me on Mastodon: @StewartLynch@iosdev.space
// 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
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)