Skip to content

Instantly share code, notes, and snippets.

View steipete's full-sized avatar

Peter Steinberger steipete

View GitHub Profile
@juliensagot
juliensagot / VariableBlurView.swift
Last active November 11, 2024 04:13
SwiftUI variable blur view
import Foundation
import SwiftUI
import UIKit
extension UIBlurEffect {
public static func variableBlurEffect(radius: Double, imageMask: UIImage) -> UIBlurEffect? {
let methodType = (@convention(c) (AnyClass, Selector, Double, UIImage) -> UIBlurEffect).self
let selectorName = ["imageMask:", "effectWithVariableBlurRadius:"].reversed().joined()
let selector = NSSelectorFromString(selectorName)
@Tunous
Tunous / SwiftUIView.swift
Created November 9, 2022 14:55
SwiftUI view wrapper for UIKit that calculates its size
import SwiftUI
final class SwiftUIView<Content: View>: UIView {
private var heightConstraint: NSLayoutConstraint?
init(content: Content, onSizeChanged: @escaping (CGSize) -> Void) {
super.init(frame: .zero)
let sizeReadingContent = content.readSize { [weak self] newSize in
@lukaskubanek
lukaskubanek / Bundle+TestFlight.swift
Last active November 3, 2024 17:20
A code snippet for detecting the TestFlight environment for a macOS app at runtime
/// MIT License
///
/// Copyright (c) 2021 Lukas Kubanek, Structured Path GmbH
///
/// 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:
@weissi
weissi / Makefile
Last active January 9, 2022 09:57
dont free
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 01:41
Attempt at organizing my context menu code better
import UIKit
class ViewController: UIViewController {
var contextMenuDataSource = CommentsContextMenuHandler()
override func viewDidLoad() {
super.viewDidLoad()
let interaction = UIContextMenuInteraction(delegate: contextMenuDataSource)
view.addInteraction(interaction)
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 April 14, 2021 01:07
Dynamic Type system fonts with custom point sizes, weight, and italics
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];
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 {
//
// EmptySwiftUIModifiers.swift
// Architectory
//
// Created by Nikita Patskov on 09.09.2020.
//
import SwiftUI
struct TestView: View {
@arroz
arroz / gist:1d2e8bc9b3103a5e903a7786c6a11534
Created March 30, 2021 15:24
Concurrent queue issue
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)