Skip to content

Instantly share code, notes, and snippets.

View aaronpearce's full-sized avatar

Aaron Pearce aaronpearce

View GitHub Profile
@christianselig
christianselig / Locale+SFSymbol.swift
Created September 3, 2021 21:54
Returns an SF Symbol currency image that match's the device's current locale, for instance dollar in North America, Indian rupee in India, etc.
extension Locale {
/// Returns an SF Symbol currency image that match's the device's current locale, for instance dollar in North America, Indian rupee in India, etc.
func currencySFSymbol(filled: Bool, withConfiguration configuration: UIImage.Configuration? = nil) -> UIImage {
// Default currency symbol will be the Animal Crossing Leaf coin 􁂬 to remain impartial to any specific country
let defaultSymbol = UIImage(systemName: "leaf.circle\(filled ? ".fill" : "")")!
guard let currencySymbolName = currencySymbolNameForSFSymbols() else { return defaultSymbol }
let systemName = "\(currencySymbolName).circle\(filled ? ".fill" : "")"
return UIImage(systemName: systemName, withConfiguration: configuration) ?? defaultSymbol
@IanKeen
IanKeen / EntryPoint.swift
Last active August 17, 2023 03:33
Example main.swift
import Foundation
import SwiftUI
let isUITesting = /* your UI test detection here */
@main
struct EntryPoint {
static func main() {
if isUITesting {
UITestApp.main()
@dimitribouniol
dimitribouniol / Bump Project Version.sh
Last active December 10, 2023 02:00
Automatically Bump Versions in Xcode
cd "${PROJECT_DIR}"
# Make sure working directory is clean.
if output=$(git status --porcelain) && [ -n "$output" ]; then
echo "error: Please commit any uncommitted files before proceeding:\n$output"
exit 1
fi
# Make sure we are on master (and not a feature branch, for instance)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
@steventroughtonsmith
steventroughtonsmith / UIView+Tooltips.h
Last active December 23, 2023 11:05
WIP tooltips for Mac Catalyst
//
// UIView+Tooltips.h
// Crossword
//
// Created by Steven Troughton-Smith on 13/09/2019.
// Copyright © 2019 Steven Troughton-Smith. All rights reserved.
//
#import <UIKit/UIKit.h>
@steipete
steipete / UIWindow+PSPDFAdditions.h
Last active June 1, 2023 18:24
Mac Catalyst: Get the NSWindow from a UIWindow (Updated for macOS 11 Big Sur, also works with Catalina)
// Don't forget to prefix your category!
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIWindow (PSPDFAdditions)
#if TARGET_OS_UIKITFORMAC
@IanKeen
IanKeen / NotificationCenter+TypeSafe.swift
Last active December 7, 2022 21:31
Type safe NotificationCenter
struct Notification<T> {
let name: NSNotification.Name
}
private let notificationData = "_notificationData"
extension NotificationCenter {
func post<T>(_ notification: Notification<T>, object: Any? = nil, data: T) {
post(name: notification.name, object: object, userInfo: [notificationData: data])
}
/**
This sample code is available under the MIT license.
*/
@available(iOS 12.0, *)
public final class ShortcutManager {
/**
This enum specifies the different intents available in our app and their various properties for the `INIntent`.
Replace this with your own shortcuts.
@IanKeen
IanKeen / ControlEventBindable.swift
Last active June 4, 2022 23:18
Easy closure based access to UIControl events (instead of target/action)
protocol ControlEventBindable: class { }
extension UIControl: ControlEventBindable { }
extension UIBarButtonItem: ControlEventBindable { }
private struct Keys {
static var EventHandlers = "_EventHandlers"
}
// MARK: - Implementation
@andrewchilds
andrewchilds / clubhouse.sh
Last active January 23, 2020 00:07
Clubhouse/git/deploy utility functions
# Clubhouse / git / deploy utility functions
#
# API docs: https://clubhouse.io/api
#
# Assuming the following:
# 1. We have a range of git commits that represent the changes being deployed
# 2. Our git branches and pull requests use the username/ch123/story-name format,
# so that "ch123" ends up in a commit message
# 3. We have a Clubhouse API token set to the $CLUBHOUSE_API_TOKEN environment variable
#
@spllr
spllr / cloudkit-request.js
Last active August 28, 2023 12:04
Setting up an authenticated CloudKit server-to-server request
/**
* Demonstrates how to use Apple's CloudKit server-to-server authentication
*
* Create private key with: `openssl ecparam -name prime256v1 -genkey -noout -out eckey.pem`
* Generate the public key to register at the CloudKit dashboard: `openssl ec -in eckey.pem -pubout`
*
* @see https://developer.apple.com/library/prerelease/ios/documentation/DataManagement/Conceptual/CloutKitWebServicesReference/SettingUpWebServices/SettingUpWebServices.html#//apple_ref/doc/uid/TP40015240-CH24-SW6
*
* @author @spllr
*/