Skip to content

Instantly share code, notes, and snippets.

Avatar

Peter Steinberger steipete

View GitHub Profile
@lukaskubanek
lukaskubanek / Bundle+TestFlight.swift
Last active May 18, 2022
A code snippet for detecting the TestFlight environment for a macOS app at runtime
View Bundle+TestFlight.swift
import Foundation
import Security
extension Bundle {
/// Returns whether the bundle was signed for TestFlight beta distribution by checking
/// the existence of a specific extension (marker OID) on the code signing certificate.
///
/// This routine is inspired by the source code from ProcInfo, the underlying library
/// of the WhatsYourSign code signature checking tool developed by Objective-See. Initially,
@weissi
weissi / Makefile
Last active Jan 9, 2022
dont free
View Makefile
CFLAGS := -O2 -fPIC
test: libdontfree.dylib test.swift
swiftc -L. -ldontfree test.swift
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^
libdontfree.dylib: dont-free.o
$(CC) $(LDFLAGS) -shared -o $@ $^
@christianselig
christianselig / context-menu.swift
Created May 6, 2021
Attempt at organizing my context menu code better
View context-menu.swift
import UIKit
class ViewController: UIViewController {
var contextMenuDataSource = CommentsContextMenuHandler()
override func viewDidLoad() {
super.viewDidLoad()
let interaction = UIContextMenuInteraction(delegate: contextMenuDataSource)
view.addInteraction(interaction)
View iOS13_onChange.swift
import SwiftUI
import Combine
public struct ChangeObserver<V: Equatable>: ViewModifier {
public init(newValue: V, action: @escaping (V) -> Void) {
self.newValue = newValue
self.newAction = action
}
private typealias Action = (V) -> Void
@jverkoey
jverkoey / UIFont+CustomizedDynamicType.m
Created Apr 14, 2021
Dynamic Type system fonts with custom point sizes, weight, and italics
View UIFont+CustomizedDynamicType.m
static const CGFloat kFontWeightEpsilon = FLT_EPSILON;
@implementation UIFont (CustomizedDynamicType)
+ (nonnull UIFont *)preferredFontWithDefaultSize:(CGFloat)size
textStyle:(nonnull UIFontTextStyle)textStyle {
return [self preferredFontWithDefaultSize:size
textStyle:textStyle
fontWeight:UIFontWeightRegular
italic:NO];
View Data+Hex.swift
extension Data {
init?(hexString: String) {
let count = hexString.count / 2
var data = Data(capacity: count)
var i = hexString.startIndex
for _ in 0 ..< count {
let j = hexString.index(after: i)
if var byte = UInt8(hexString[i ... j], radix: 16) {
data.append(&byte, count: 1)
} else {
View EmptySwiftUIModifiers.swift
//
// EmptySwiftUIModifiers.swift
// Architectory
//
// Created by Nikita Patskov on 09.09.2020.
//
import SwiftUI
struct TestView: View {
View gist:1d2e8bc9b3103a5e903a7786c6a11534
let queue = DispatchQueue(label: "Queue", qos: .default, attributes: [.concurrent], autoreleaseFrequency: .workItem, target: .global(qos: .default))
let cancellable = [1, 2, 3, 4, 5].publisher
.receive(on: queue)
.map { longRunningFunc(value: $0) }
.receive(on: DispatchQueue.main)
.sink (receiveCompletion: { completion in
Swift.print(completion)
}, receiveValue: { value in
Swift.print(value)
@schwa
schwa / environment.swift
Created Mar 27, 2021
Dash Snippet for SwiftUI Environments & Modifiers
View environment.swift
struct __ValueType__ {
}
struct __ValueType__Key: EnvironmentKey {
static var defaultValue = __ValueType__()
}
extension EnvironmentValues {
var __KeyName__: __ValueType__ {
get {
View Result+Catch.swift
extension Result {
public func `catch`(_ handler: () throws -> Success) -> Result<Success, Error> {
flatMapError { _ in
.init { try handler() }
}
}
public func `catch`(_ handler: (Failure) throws -> Success) -> Result<Success, Error> {
flatMapError { error in
.init { try handler(error) }