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 | |
enum OSDocumentError: Error { | |
case unknownFileFormat | |
} | |
#if canImport(UIKit) | |
import UIKit |
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 | |
import UIKit | |
private struct BodyCounterView: UIViewRepresentable { | |
let color: UIColor | |
private let id = UUID() // Force view updates | |
func makeUIView(context: Context) -> _BodyCounterView { | |
let view = _BodyCounterView() |
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
// | |
// PagingView.swift | |
// Wallaroo - https://wallaroo.app | |
// | |
// Created by Sean Heber (@BigZaphod) on 8/9/22. | |
// | |
import SwiftUI | |
// This exists because SwiftUI's paging setup is kind of broken and/or wrong out of the box right now. |
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
// Structure of _StackLayoutCache and related types. | |
// Used by SwiftUI as the Cache type for VStackLayout and HStackLayout. | |
// | |
// As of: iOS 16.0 simulator in Xcode 14.0b6 | |
import SwiftUI | |
struct _StackLayoutCache { | |
var stack: StackLayout | |
} |
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 | |
struct MyValue: _ViewTraitKey { | |
static var defaultValue: Int = 0 | |
} | |
extension View { | |
func myValue(_ value: Int) -> some View { | |
_trait(MyValue.self, value) | |
} |
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
// A heterogeneous dictionary with strong types in Swift, https://oleb.net/2022/heterogeneous-dictionary/ | |
// Ole Begemann, April 2022 | |
/// A key in a `HeterogeneousDictionary`. | |
public protocol HeterogeneousDictionaryKey { | |
/// The "namespace" the key belongs to. Every `HeterogeneousDictionary` has its associated domain, | |
/// and only keys belonging to that domain can be stored in the dictionary. | |
associatedtype Domain | |
/// The type of the values that can be stored under this key in the dictionary. | |
associatedtype Value |
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 View { | |
func cascadingAction<ActionInput>(path: CascadingActionNodeModifier<ActionInput>.Path, handler: @escaping (ActionInput) -> Void) -> some View { | |
self.modifier(CascadingActionNodeModifier(path: path, handler: handler)) | |
} | |
func cascadingAction(path: CascadingActionNodeModifier<Void>.Path, handler: @escaping () -> Void) -> some View { | |
self.modifier(CascadingActionNodeModifier(path: path, handler: handler)) | |
} |
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
// Copyright 2021 Kyle Hughes | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | |
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | |
// permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | |
// Software. | |
// |
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 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 |
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
// Simplified version of https://gist.github.com/anandabits/d9494d14fef221983ff4f1cafa318d47#file-areequatablyequal-swift | |
func isEqual(x: Any, y: Any) -> Bool { | |
func f<LHS>(_ lhs: LHS) -> Bool { | |
let p = Wrapper<LHS>.self as? AnyEquatable.Type | |
return p?.isEqual(x, y) ?? false | |
} | |
return _openExistential(x, do: f) | |
} |
NewerOlder