Skip to content

Instantly share code, notes, and snippets.

Felix M. fxm90

View GitHub Profile
@fxm90
fxm90 / ScreenOverlayViewModel.swift
Last active Oct 14, 2019
Example on how to elegantly test a delegate protocol.
View ScreenOverlayViewModel.swift
//
// 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 Sep 23, 2019
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.
View UIColor+MakeDynamicColor.swift
//
// 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 Sep 1, 2019
Check "SwiftFormat" installed via CocoaPods. Add a new "Run Script Phase" with this gist.
View swiftformat.sh
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 Oct 24, 2019
Wrapper around `dataTask(with, completionHandler:)` that uses swifts result type in the completion handler.
View URLSession+Result.swift
//
// 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 Jun 16, 2019
A lightweight implementation of an observable sequence that you can subscribe to.
View Observable.swift
//
// For reusability reasons I've moved the code into a Framework.
// https://github.com/fxm90/LightweightObservable
//
@fxm90
fxm90 / UIView+AnimateAlpha.swift
Last active Jun 29, 2020
Animate the `alpha` value of a UIView and update the `isHidden` flag accordingly.
View UIView+AnimateAlpha.swift
//
// 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 Feb 11, 2019
An image view containing a vertical gradient as background.
View VerticalGradientImageView.swift
//
// 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 May 21, 2020
A simple log extension on `String` using literal expressions
View String+Log.swift
//
// 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
Created Aug 6, 2018
XCTest - Use custom notification center in test case and assert notification (not) triggered.
View CustomNotificationCenterTestCase.swift
class CustomNotificationCenterTestCase: XCTestCase {
var notificationCenter: NotificationCenter!
override func setUp() {
super.setUp()
notificationCenter = NotificationCenter()
}
@fxm90
fxm90 / NotificationTestCase.swift
Last active Apr 8, 2020
XCTest - Assert notification (not) triggered.
View NotificationTestCase.swift
import XCTest
class NotificationTestCase: XCTestCase {
func testTriggerNotification() {
expectation(forNotification: .fooBar,
object: nil,
handler: nil)
let notificationCenter = NotificationCenter.default
You can’t perform that action at this time.