Skip to content

Instantly share code, notes, and snippets.

Working from home

Shaps shaps80

Working from home
View GitHub Profile
shaps80 / Flipped.swift
Created Feb 19, 2021
Provides a CGAffineTransform suitable for flipping the Y Axis.
View Flipped.swift
private func flipped(size: CGSize) -> CGAffineTransform {
let mirror = CGAffineTransform(scaleX: 1, y: -1)
let translate = CGAffineTransform(translationX: 0, y: size.height)
return mirror.concatenating(translate)
shaps80 / SwiftUIView.swift
Created Feb 10, 2021
Demonstrates an approach for dismissing a SwiftUI view presented via a UIHostingController
View SwiftUIView.swift
struct SwiftUIView: View {
@ObservedObject var delegate: SheetDismisser
@Environment(\.presentationMode) var presentationMode
var body: some View {
Button(action: {
self.presentationMode.wrappedValue.dismiss() // SwiftUI
self.delegate.dismiss() // UIKit
}) {
View Print-JSON.swift
extension Encodable {
var debugJson: String {
(try? JSONEncoder().encode(self).debugJson) ?? ""
extension Data {
var debugJson: String {
String(decoding: self, as: UTF8.self)
shaps80 /
Last active Dec 17, 2020
Strip Intel architecture's from Xcode frameworks for use on Apple Silicon
# Usage example: ./
# This script is design to remove Intel architecture's from Xcode frameworks
# to enable development and installation of 3rd party pre-compiled frameworks
# that are not currently distributed as either XCFramework or SPM packages.
# The most common use-case would be carthage dependencies that are distributed
View ConditionalModifier.swift
extension View {
/// Conditionally apply modifiers to a view.
func `if`<Content: View>(_ condition: () -> Bool, content: (Self) -> Content) -> some View {
condition() ?
ViewBuilder.buildEither(first: content(self)) :
ViewBuilder.buildEither(second: self)
func `if`<Content: View>(_ condition: @autoclosure () -> Bool, content: (Self) -> Content) -> some View {
condition() ?
shaps80 / Models.swift
Last active Jan 9, 2021
Swift type for representing a UserAgent (includes an implementation similar of Apple’s Version from SPM)
View Models.swift
import UIKit
extension UIDevice {
List can be updated here:
internal static var models: String = """
shaps80 / ActivityView.swift
Created Nov 27, 2020
A complete SwiftUI UIActivityViewController implementation.
View ActivityView.swift
import SwiftUI
import LinkPresentation
import CoreServices
struct ActivityView: UIViewControllerRepresentable {
private let activityItems: [Any]
private let applicationActivities: [UIActivity]?
private let completion: UIActivityViewController.CompletionWithItemsHandler?
shaps80 / ScaledMetric.swift
Created Oct 9, 2020
A ScaledMetric implementation that is supported in iOS13+
View ScaledMetric.swift
import SwiftUI
#if swift(>=14)
public typealias ScaledMetric = SwiftUI.ScaledMetric
public typealias ScaledMetric = ScaledMetricCompat
/// A dynamic property that scales a numeric value.
shaps80 / SwiftUI-TextView.swift
Last active May 16, 2021
A SwiftUI view that wraps a UITextView but provides almost all functionality though modifiers and attempts to closely match the Text/TextField components.
View SwiftUI-TextView.swift
The font modifier requires the following gist:
shaps80 / UIFont+Helpers.swift
Last active Mar 18, 2021
A set of UIFont helpers that matches the equivalent SwiftUI Font API.
View UIFont+Helpers.swift
import UIKit
public extension UIFont {
enum Leading {
case loose
case tight
private func addingAttributes(_ attributes: [UIFontDescriptor.AttributeName: Any]) -> UIFont {