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
class ShadowCutoutView: UIView { | |
var contentView: UIView? { | |
didSet { | |
oldValue?.removeFromSuperview() | |
guard let contentView else { | |
return | |
} | |
contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight] |
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
extension UIViewController { | |
/// A property wrapper that loads the view controller’s view before accessing the property. | |
/// A backport of `@ViewLoading` property wrapper, available in iOS 16.4. | |
/// https://developer.apple.com/documentation/uikit/uiviewcontroller/viewloading | |
@propertyWrapper | |
struct ViewLoader<Value> { | |
static subscript<T: UIViewController>( | |
_enclosingInstance instance: T, | |
wrapped wrappedKeyPath: ReferenceWritableKeyPath<T, Value>, | |
storage storageKeyPath: ReferenceWritableKeyPath<T, Self> |
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
extension UIView { | |
struct LabeledEdge: OptionSet { | |
let rawValue: Int | |
static let leading = Self(rawValue: 1 << 0) | |
static let top = Self(rawValue: 1 << 1) | |
static let trailing = Self(rawValue: 1 << 2) | |
static let bottom = Self(rawValue: 1 << 3) | |
static let all: Self = [.leading, .top, .trailing, .bottom] |
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
func XCTAssertSuccess<T, U>( | |
_ result: @autoclosure () throws -> Result<T, U>, | |
_ message: @autoclosure () -> String = "", | |
file: StaticString = #filePath, | |
line: UInt = #line | |
) -> T { | |
do { | |
let value = try result() | |
switch value { |
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
extension Result where Success == Void { | |
static var success: Result<Success, Failure> { | |
return .success(()) | |
} | |
} | |
// Example usage | |
func someFunctionThatReturnsResult() -> Result<Void, Error> { | |
// Allows to use just `.success` instead of `.success(())` |