Skip to content

Instantly share code, notes, and snippets.

View BrentMifsud's full-sized avatar

Brent Mifsud BrentMifsud

View GitHub Profile
@BrentMifsud
BrentMifsud / UITestHelpers.swift
Last active February 16, 2023 02:17
Xcode UI Testing Helpers
import XCTest
/// Bundle identifiers for apples native apps. Used to open other apps during UI testing.
///
/// More can be found here: https://support.apple.com/en-ca/guide/deployment/depece748c41/web
enum AppleBundleIdentifiers: String {
case safari = "com.apple.mobilesafari"
case springboard = "com.apple.springboard"
}
@BrentMifsud
BrentMifsud / AsyncSequence+AsyncStreamInitializer.swift
Last active July 24, 2023 20:34
Convenience methods for converting any async sequence into an async stream
fileprivate extension AsyncStream {
init<Base: AsyncSequence>(from sequence: Base, file: StaticString = #filePath, line: UInt = #line) where Element == Base.Element {
var iterator = sequence.makeAsyncIterator()
// FIXME: In later swift versions, AsyncSequence protocol will likely have an associated error type.
// FIXME: For now, produce an assertionFailure to let developer know to use an AsyncThrowingStream instead.
self.init {
do {
return try await iterator.next()
} catch {
assertionFailure("warning: Base AsyncSequence threw an error. Use AsyncThrowingStream instead", file: file, line: line)
@BrentMifsud
BrentMifsud / Flow.swift
Last active December 18, 2023 22:19
A view that renders its children in a flow layout
import SwiftUI
/// A layout that presents its children in a flow layout
/// Thanks to [objc.io](https://talk.objc.io/episodes/S01E308-the-layout-protocol?t=489) for the starting point
/// Added some additional changes here to support view spacing and resizing of subviews that are larger than the container.
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *)
public struct FlowLayout: Layout {
private let spacing: CGFloat
public init(spacing: CGFloat = 8) {