Skip to content

Instantly share code, notes, and snippets.

View couchdeveloper's full-sized avatar

Andreas Grosam couchdeveloper

View GitHub Profile
@rjchatfield
rjchatfield / ArrayBuilder.swift
Last active September 7, 2023 07:20
ArrayBuilder - Swift ~~FunctionBuilder~~ ResultBuilder
@resultBuilder
public struct ArrayBuilder<Element> {
public static func buildPartialBlock(first: Element) -> [Element] { [first] }
public static func buildPartialBlock(first: [Element]) -> [Element] { first }
public static func buildPartialBlock(accumulated: [Element], next: Element) -> [Element] { accumulated + [next] }
public static func buildPartialBlock(accumulated: [Element], next: [Element]) -> [Element] { accumulated + next }
// Empty Case
public static func buildBlock() -> [Element] { [] }
// If/Else
@marcpalmer
marcpalmer / ScrollViewSnapIssue.swift
Last active October 22, 2023 06:19
Updated to correct problem with subscription being new every time state changes, fixed scrollTo so it works
import Combine
import SwiftUI
struct SnapPointPreferenceData {
let frame: Anchor<CGRect>
}
struct SnapPointPreferenceKey: PreferenceKey {
typealias Value = SnapPointPreferenceData?
@HiddenJester
HiddenJester / UnitTestingSceneDelegateGist.md
Last active March 20, 2024 14:38
Mocking SceneDelegate for Unit Tests on iOS 13

Replacing the SceneDelegate When Running Unit Tests

Overview

I've been working through the exercises in the excellent iOS Unit Testing by Example book by Jon Reid, which I highly recommend. However, the book is in beta at the moment and there are some curveballs thrown by iOS 13 that aren't handled in the text yet. Specifically, when I hit the section about using a testing AppDelegate class I thought "This is very good. But what about the SceneDelegate?"

In Chapter 4 the recommendation is to remove the @UIApplicationMain decoration and make a manual top-level call to UIApplicationMain. To wit:

import UIKit
@AliSoftware
AliSoftware / Bindings.swift
Last active May 4, 2024 06:18
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
@ilessing
ilessing / Pandoc Markdown to PDF.md
Last active April 26, 2024 22:15
getting pandoc to generate PDF from Markdown on MacOS

Using Pandoc to generate PDFs from Markdown

on a Mac running macOS 10.13.4

To install the needed components you can use Homebrew

Two Components are needed:

@rbuckton
rbuckton / CancellationToken.md
Last active June 26, 2021 20:58
External Cancellation of Promises with CancellationTokenSource
#!/bin/bash
# This script automatically sets the version and short version string of
# an Xcode project from the Git repository containing the project.
#
# To use this script in Xcode, add the script's path to a "Run Script" build
# phase for your application target.
set -o errexit
set -o nounset
@rob-murray
rob-murray / set_agv_ver.sh
Last active July 1, 2022 01:31
Use agvtool to set Xcode project build number
#!/bin/bash
#
# Use agvtool to set Xcode project build number and create git tag
# Note: requires Xcode project configured to use Apple Generic Versioning and git
#
# Usage: set_agv_ver.sh 123
#
# src: https://gist.github.com/rob-murray/8644974
#
@couchdeveloper
couchdeveloper / RXTimer.h
Last active July 29, 2019 06:55
A timer based on dispatch_source_create() Objective-C
//
// RXTimer.h
//
// Copyright 2013 Andreas Grosam
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@couchdeveloper
couchdeveloper / RXAsynchronousOperation.h
Last active December 29, 2015 12:09
A RXStreamToStreamCopier asynchronously copies the content of a source stream into a destination stream.
//
// RXAsynchronousOperation.h
//
// Copyright 2013 Andreas Grosam
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0