Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Shaps shaps80

🏠
Working from home
View GitHub Profile
@shaps80
shaps80 / swift-package-collection.json
Last active Nov 5, 2021
Swift Package Collection Sample
View swift-package-collection.json
{
"name": "",
"overview": "",
"keywords": ["swift"],
"packages": [
{
"url": "",
},
],
"author": {
@shaps80
shaps80 / Store.swift
Created Jun 14, 2021
Atomic RangeReplaceableCollection Storage in Swift
View Store.swift
import Foundation
public final class Store<Element>: RangeReplaceableCollection {
public typealias Index = Int
public typealias SubSequence = Store<Element>
public var startIndex: Index { queue.sync { storage.startIndex } }
public var endIndex: Index { queue.sync { storage.endIndex } }
public func index(after i: Index) -> Index { queue.sync { storage.index(after: i) } }
@shaps80
shaps80 / UIMenu+ResultBuilder.swift
Created Jun 9, 2021
Adds ResultBuilder support to UIMenu to simplify creation
View UIMenu+ResultBuilder.swift
import SwiftUI
typealias Menu = UIMenu
typealias Action = UIAction
@resultBuilder
struct MenuElementBuilder {
static func buildBlock(_ components: UIMenuElement...) -> [UIMenuElement] { components }
}
@shaps80
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)
}
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
shaps80 / strip-intel.sh
Last active Dec 17, 2020
Strip Intel architecture's from Xcode frameworks for use on Apple Silicon
View strip-intel.sh
#!/bin/sh
# strip-intel.sh
# Usage example: ./strip-intel.sh
# 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
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:
https://gist.github.com/adamawolf/3048717
*/
internal static var models: String = """
@shaps80
shaps80 / ActivityView.md
Last active Sep 9, 2021
A complete SwiftUI UIActivityViewController implementation.
View ActivityView.md
@shaps80
shaps80 / SwiftUI-TextView.md
Last active Sep 7, 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.md