Skip to content

Instantly share code, notes, and snippets.

View atierian's full-sized avatar

Ian Saultz atierian

  • Charleston, SC
View GitHub Profile
@atierian
atierian / AnyCodingKey.swift
Created September 7, 2021 15:24
Top Level Key Decoding
struct AnyCodingKey: CodingKey {
var stringValue: String
var intValue: Int?
init(stringValue: String) {
self.stringValue = stringValue
self.intValue = nil
}
init(intValue: Int) {
@atierian
atierian / Publisher+Result.swift
Last active September 30, 2021 12:41 — forked from IanKeen/Publisher+Result.swift
Extension to convert a failable Publisher into a non-failable Result based publisher (as well as extensions to break out values/errors) - Same idea as RxSwifts Materialize
extension Publisher {
func asResult() -> AnyPublisher<Result<Output, Failure>, Never> {
return map(Result.success)
.catch { Just(Result.failure($0)) }
.eraseToAnyPublisher()
}
}
extension Publisher {
func values<S, F: Error>() -> AnyPublisher<S, Never> where Output == Result<S, F>, Failure == Never {
@atierian
atierian / MyCell.swift
Created October 28, 2021 14:43
Oversimplified Example of MVVM
class MyCell: UITableViewCell {
let titleLabel = UILabel()
let subtitleLabel = UILabel()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init?(coder: NSCoder) { nil }
@atierian
atierian / AsyncToCompletionHandlers.swift
Created November 8, 2021 16:41
Going from async to completion handlers.
import UIKit
enum SomeError: Error {
case foo, bar, baz, unknown
}
struct SDK {
func simpleAsync() async -> Int {
try? await Task.sleep(seconds: 2)
return 42
@atierian
atierian / Concurrency.swift
Last active November 10, 2021 14:24
Comparison of App Sizes when including the concurrency backport. Compiled with Xcode 13.2 beta.
import UIKit
class ViewController: UIViewController {
let label = UILabel()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(label)
@atierian
atierian / README.md
Last active July 30, 2025 03:41
Allow consumers of SwiftUI UIViewRepresentable conforming Views to inject wrapped UIView delegate implementations through ViewModifiers using a ProxyDelegate.

Allow the consumer of a SwiftUI UIViewRepresentable View to inject delegate implementations for the wrapped UIView through View Modifiers by using a proxy delegate.

This can be a helpful pattern when providing a SwiftUI wrapper for a very heavy and complex UIView, where the wrapper implements many of the delegate methods of the wrapped UIView. But you want someone consuming the wrapper to have the ability to inject their own delegate method implementations to override yours, or to leverage some of the methods your not implementing.

@atierian
atierian / AsyncSequenceExample.swift
Created August 12, 2022 18:00
Subscribing to AsyncSequence vs Combine Publisher
actor Counter: AsyncSequence {
typealias Element = Int
let limit: Int
var current = 1
init(limit: Int, current: Int = 1) {
self.limit = limit
self.current = current
}
@atierian
atierian / CrossModuleGenericLifting.swift
Last active January 25, 2023 17:47
(ab)using enum pattern matching to lift generic types to specific types and vice-versa in a type-safe way
// MARK: Interface Module
struct Request<Output> {
let kind: Kind
enum Kind {
case one((Int) -> Output)
case two((String) -> Output)
}
}
@dynamicMemberLookup
struct Identified<Value> {
let value: Value
let id: String
subscript<T>(dynamicMember keyPath: KeyPath<Value, T>) -> T {
value[keyPath: keyPath]
}
}
#!/bin/bash
echo "🧪 scanning for shell injection"
semgrep --config="r/yaml.github-actions.security.run-shell-injection.run-shell-injection"
echo "\n\n"
echo "🧪 scanning for target code checkout"
semgrep --config="r/yaml.github-actions.security.pull-request-target-code-checkout.pull-request-target-code-checkout"
echo "\n\n"