This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
private extension Task where Failure == any Error { | |
static var backoffMultiplier: Int { | |
2 | |
} | |
static func incrementRetryValues(currentRetry: inout Int, currentDelay: inout Int) { | |
currentRetry += 1 | |
currentDelay = currentRetry == 0 ? 100 : currentDelay * Self.backoffMultiplier |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
public extension View { | |
func onSafeAreaChange(onChange: @escaping (EdgeInsets) -> Void) -> some View { | |
modifier(SafeAreaReader(onChange: onChange)) | |
} | |
} | |
internal struct SafeAreaReader: ViewModifier { | |
var onChange: (EdgeInsets) -> Void |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
public extension View { | |
/// Exposes the size of the specified view | |
/// - Parameter onChange: This function will be called when the size of a view changes. | |
/// - Returns: some View | |
func onSizeChange(onChange: @escaping (CGSize) -> Void) -> some View { | |
modifier(SizeReader(onChange: onChange)) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
/// Static properties for all preview devices. | |
/// | |
/// Usage: | |
/// | |
/// ```swift | |
/// struct TestView_Previews: PreviewProvider { | |
/// static var previews: some View { | |
/// Group { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/// Standard HTTP Methods | |
enum HTTPMethod: String { | |
case options = "OPTIONS" | |
case get = "GET" | |
case head = "HEAD" | |
case post = "POST" | |
case put = "PUT" | |
case patch = "PATCH" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Resizes to fit its content. Or until size reaches provided constraints. | |
final class ContentResizingTableView: UITableView { | |
override var contentSize: CGSize { | |
didSet { | |
invalidateIntrinsicContentSize() | |
} | |
} | |
override var intrinsicContentSize: CGSize { | |
layoutIfNeeded() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Property wrapper that provides control over whether to explicitly encode nil values to json or not. | |
/// - Parameters: | |
/// - wrappedValue: the value to be encoded. | |
/// - encodeNil: Should the value be explicitly encoded as "null" in json if nil. | |
/// - Note: | |
/// Usage: | |
/// | |
/// ```swift | |
/// struct MyStruct: Codable { | |
/// @NilCodable var myNullable: String? // defaults to omitting null (codable default behavior) |
NewerOlder