Skip to content

Instantly share code, notes, and snippets.

@fxm90
fxm90 / Combine-PassthroughSubject-CurrentValueSubject.swift
Last active November 17, 2021 00:51
Playground showing the difference between a `PassthroughSubject` and a `CurrentValueSubject`
//
// Combine-PassthroughSubject-CurrentValueSubject.playground
//
// Created by Felix Mau on 30.07.20.
// Copyright © 2020 Felix Mau. All rights reserved.
//
import PlaygroundSupport
import Combine
@fxm90
fxm90 / ScreenOverlayViewModel.swift
Last active January 25, 2026 15:12
Example on how to elegantly test a delegate protocol.
//
// ScreenOverlayViewModel.swift
//
// Created by Felix Mau on 12.10.19.
// Copyright © 2019 Felix Mau. All rights reserved.
//
import Foundation
protocol ScreenOverlayViewModelDelegate: AnyObject {
@fxm90
fxm90 / UIColor+MakeDynamicColor.swift
Last active January 25, 2026 14:54
Creates an instance of `UIColor`, that generates its color data dynamically based on the current `userInterfaceStyle`. Furthermore this method falls back to the `lightVariant` color for iOS versions prior to iOS 13.
//
// UIColor+MakeDynamicColor.swift
//
// Created by Felix Mau on 22/09/19.
// Copyright © 2019 Felix Mau. All rights reserved.
//
import Foundation
extension UIColor {
@fxm90
fxm90 / swiftformat.sh
Created September 1, 2019 10:20
Check "SwiftFormat" installed via CocoaPods. Add a new "Run Script Phase" with this gist.
SWIFTFORMAT="${PODS_ROOT}/SwiftFormat/CommandLineTool/swiftformat"
if [ ! -f "$SWIFTFORMAT" ]; then
echo "warning: SwiftFormat not installed!"
exit 1
fi
$SWIFTFORMAT ./
@fxm90
fxm90 / Observable.swift
Last active June 16, 2019 14:23
A lightweight implementation of an observable sequence that you can subscribe to.
//
// For reusability reasons I've moved the code into a Framework.
// https://github.com/fxm90/LightweightObservable
//
@fxm90
fxm90 / UIView+AnimateAlpha.swift
Last active January 31, 2026 10:00
Animates the `alpha` value of a UIView and updates the `isHidden` flag accordingly.
//
// UIView+AnimateAlpha.swift
//
// Created by Felix Mau on 17.12.18.
// Copyright © 2018 Felix Mau. All rights reserved.
//
import UIKit
/// Convenience animation helpers for `GradientActivityIndicatorView` that
@fxm90
fxm90 / VerticalGradientImageView.swift
Last active January 25, 2026 14:49
An image view containing a vertical gradient as background.
//
// VerticalGradientImageView.swift
//
// Created by Felix Mau on 23/09/18.
// Copyright © 2018 Felix Mau. All rights reserved.
//
import UIKit
final class VerticalGradientImageView: UIImageView {
@fxm90
fxm90 / String+Log.swift
Last active February 9, 2026 20:37
A simple log extension on `String` using literal expressions
//
// String+Log.swift
//
// Created by Felix Mau on 16.09.18.
// Copyright © 2018 Felix Mau. All rights reserved.
//
import Foundation
extension String {
@fxm90
fxm90 / CustomNotificationCenterTestCase.swift
Last active January 25, 2026 15:07
XCTest - Assert notification is (not) posted when using a custom notification center.
import XCTest
@MainActor
final class CustomNotificationCenterTestCase: XCTestCase {
func test_notification_isPosted() {
// Given
let notificationCenter = NotificationCenter()
let notificationExpectation = XCTNSNotificationExpectation(
name: .fooBar,
@fxm90
fxm90 / NotificationTestCase.swift
Last active January 25, 2026 15:06
XCTest - Assert notification is (not) posted.
import XCTest
@MainActor
final class NotificationTestCase: XCTestCase {
func test_notification_isPosted() {
// Given
expectation(
forNotification: .fooBar,
object: nil,