Skip to content

Instantly share code, notes, and snippets.

View bok-'s full-sized avatar

Rob Amos bok-

  • Melbourne, Australia
View GitHub Profile
// An exercise in implementing `@Invalidating` for UIView before Xcode 13.0 beta 2
// was released, rendering it unnecessary
import UIKit
public extension UIView {
@propertyWrapper
class Invalidating<Value> where Value: Equatable {
@_functionBuilder
public enum CollectionBuilder<Component> {
// MARK: - Building Expressions
/// Basic uplift of an `Expression` into a `Component` (aka `[Expression]`)
///
public static func buildExpression(_ expression: Component) -> [Component] {
[expression]
}
import Foundation
public extension JSONDecoder.DateDecodingStrategy {
static var betterISO8601: JSONDecoder.DateDecodingStrategy {
return .custom({ try decodeDate(from: $0, calendar: Calendar(identifier: .gregorian)) })
}
static func betterISO8601 (calendar: Calendar) -> JSONDecoder.DateDecodingStrategy {
return .custom({ try decodeDate(from: $0, calendar: calendar) })
}
@bok-
bok- / CollectionBuilder.swift
Created August 27, 2020 00:38
Genericised @_functionBuilder that appends to mutable collections
@_functionBuilder
public enum CollectionBuilder<Element>: SimpleBuilder {
public typealias Component = Element
}
public extension RangeReplaceableCollection {
mutating func collect (@CollectionBuilder<Element> _ builder: () -> Element) {
append(builder())
}
@bok-
bok- / FileMonitorPublisher.swift
Last active June 3, 2022 06:18
A simple Combine Publisher that adds a `URL.publisher` to monitor for file changes
//
// FileMonitorPublisher.swift
// Longinus
//
// Created by Rob Amos on 3/3/20.
//
import Foundation
import Combine
@bok-
bok- / SVGImages.md
Created September 11, 2019 01:45
SVG Images with Macaw

SVG Images with Macaaw

Using Macaw its pretty straight forward to use SVG images in your iOS and macOS apps.

Installation

Install via CocoaPods or Carthage. It doesn't support SPM at the time of writing but its pretty easy to fork their repo and add it.

Usage

import Foundation
import Combine
@_functionBuilder
public struct AnyCancellableBuilder {
public static func buildBlock () -> [AnyCancellable] {
return []
}
public static func buildBlock (_ child: AnyCancellable) -> [AnyCancellable] {
//
// GridTest.swift
//
import SwiftUI
struct GridTest: View {
var items: [String]
var body: some View {
@bok-
bok- / Makefile
Created May 7, 2019 05:11
Getting up and running with Swift on AWS Lambda
#
# Makefile for Cards Deployment
#
PACKAGE = lambda.zip
PROFILE = unsignedapps
REGION = ap-southeast-2
LAMBDA = Cards
SWIFT_DOCKER_IMAGE = swift:5.0
import UIKit
class ViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillResize(_:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
}
override func viewWillDisappear(_ animated: Bool) {