Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / Font+Formatting.swift
Last active June 28, 2021 07:50
Extension that converts Strings with basic HTML tags to SwiftUI's Text (Supports SwiftUI 1.0 / iOS 13.0).
//
// Font+Formatting.swift
//
// Created by Felix Mau on 12.11.20.
// Copyright © 2020 Felix Mau. All rights reserved.
//
import Foundation
import SwiftUI
@fxm90
fxm90 / Dictionary+PlusAssignment.swift
Last active June 14, 2021 09:53
Combine two dictionaries of same type with custom operator.
extension Dictionary {
/// Combine two dictionaries of same type with `+` operator.
///
/// - Important: When `left` and `right` are having a same key, the value from `right` will override
/// the value from `left`. E.g.
/// ```
/// var left = ["a": 1, "b": 2]
/// let right = ["a": 3, "c": 4]
/// left += right
/// print(left)
@fxm90
fxm90 / Dictionary+MapKeys.swift
Created June 14, 2021 07:31
Counterpart methods to `mapValues(_:)` and `compactMapValues(_:)`
//
// Dictionary+MapKeys.swift
//
// Created by Felix Mau on 14.06.21.
// Copyright © 2021 Felix Mau. All rights reserved.
//
extension Dictionary {
/// Returns a new dictionary containing the keys transformed by the given closure.
/// The values of this dictionary stay the same.
@fxm90
fxm90 / ColoredToggleStyle.swift
Last active May 26, 2021 06:20
A fully configurable toggle style for SwiftUI.
//
// ColoredToggleStyle.swift
//
// Created by Felix Mau on 29.03.2021.
// Copyright © 2021 Felix Mau. All rights reserved.
//
/// A fully configurable toggle style.
struct ColoredToggleStyle: ToggleStyle {
@fxm90
fxm90 / CombinePublishedVsCurrentValueSubject.swift
Last active May 2, 2021 17:38
Gist showing the difference between the property wrapper `@Published` and a `CurrentValueSubject`
//
// CombinePublishedVsCurrentValueSubject.playground
//
// Created by Felix Mau on 09.02.21.
// Copyright © 2021 Felix Mau. All rights reserved.
//
import Foundation
import Combine
@fxm90
fxm90 / PDFBase64ToImageViewController.swift
Created April 20, 2021 12:15
Playground showing how to convert a base 64 encoded PDF to an UIImage.
//
// PDFBase64ToImageViewController.swift
//
// Created by Felix Mau on 20.04.21.
// Copyright © 2021 Felix Mau. All rights reserved.
//
import PlaygroundSupport
import UIKit
import PDFKit
@fxm90
fxm90 / UIColor+Initializers.swift
Last active August 11, 2020 08:45
Create UIColor from RGB, RGBA, Hex or Hex-String ("#ffffff")
public extension UIColor {
/// Create color from RGB(A)
///
/// Parameters:
/// - absoluteRed: Red value (between 0 - 255)
/// - green: Green value (between 0 - 255)
/// - blue: Blue value (between 0 - 255)
/// - alpha: Blue value (between 0 - 255)
///
@fxm90
fxm90 / NotificationTestCase.swift
Last active April 8, 2020 12:58
XCTest - Assert notification (not) triggered.
import XCTest
class NotificationTestCase: XCTestCase {
func testTriggerNotification() {
expectation(forNotification: .fooBar,
object: nil,
handler: nil)
let notificationCenter = NotificationCenter.default