Skip to content

Instantly share code, notes, and snippets.

@fxm90
fxm90 / Combine-CLLocationManagerDelegate.swift
Last active July 13, 2023 09:15
Playground showing how to convert a delegate pattern to combine publishers.
//
// Combine-CLLocationManagerDelegate.playground
//
// Created by Felix Mau on 30.07.20.
// Copyright © 2020 Felix Mau. All rights reserved.
//
import PlaygroundSupport
import Combine
import CoreLocation
@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 May 9, 2022 14:46
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.
//
protocol ScreenOverlayViewModelDelegate: AnyObject {
func screenOverlayViewModelDidUpdate(alpha: CGFloat)
}
@fxm90
fxm90 / UIColor+MakeDynamicColor.swift
Last active September 23, 2019 15:37
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 / URLSession+Result.swift
Last active October 24, 2019 06:28
Wrapper around `dataTask(with, completionHandler:)` that uses swifts result type in the completion handler.
//
// URLSession+Result.swift
// HttpRequestSample
//
// Created by Felix Mau on 08/16/19.
// Copyright © 2019 Felix Mau. All rights reserved.
//
import Foundation
@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 December 22, 2021 19:31
Animate the `alpha` value of a UIView and update the `isHidden` flag accordingly.
//
// UIView+AnimateAlpha.swift
//
// Created by Felix Mau on 17/12/18.
// Copyright © 2018 Felix Mau. All rights reserved.
//
import UIKit
extension UIView {
@fxm90
fxm90 / VerticalGradientImageView.swift
Last active February 11, 2019 13:19
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
class VerticalGradientImageView: UIImageView {
@fxm90
fxm90 / String+Log.swift
Last active February 4, 2023 17:47
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 {