Skip to content

Instantly share code, notes, and snippets.


Magnus Jensen magnuskahr

View GitHub Profile
View FullscreenOverlay.swift
extension View {
func fullscreenOverlay<Overlay: View>(isPresented show: Binding<Bool>, @ViewBuilder overlay: () -> Overlay) -> some View {
background {
FullscreenOverlayPresenter(show: show, overlay: overlay())
struct FullscreenOverlayPresenter<Overlay: View>: UIViewControllerRepresentable {

SE-0401: unimport for cleaning up files


Initialization and deinitalization are important parts of how we create structs and classes in Swift. Being a bit more abstract, we have files that can import other modules to expand local capabilities using the import keyword, however, the reversed ain’t true, requiring developers to hassle with imported functionality at lines were it ain’t used.

magnuskahr / ValueToggle.swift
Last active Jan 14, 2022
A SwiftUI toggle to switch on/off a value for an optional state
View ValueToggle.swift
struct ValueToggle<Value, Label: View>: View {
@Binding var value: Value?
let onValue: Value
let label: () -> Label
@State private var isOn = false
var body: some View {
Toggle(isOn: $isOn, label: label)
View CascadingAction.swift
import SwiftUI
extension View {
func cascadingAction<ActionInput>(path: CascadingActionNodeModifier<ActionInput>.Path, handler: @escaping (ActionInput) -> Void) -> some View {
self.modifier(CascadingActionNodeModifier(path: path, handler: handler))
func cascadingAction(path: CascadingActionNodeModifier<Void>.Path, handler: @escaping () -> Void) -> some View {
self.modifier(CascadingActionNodeModifier(path: path, handler: handler))
magnuskahr / UnwrappingButton.swift
Last active Dec 11, 2021
Need to show a button that is always visible and which action relies on a value, but disabled if the value is missing? Use UnwrappingButton for an easy solution.
View UnwrappingButton.swift
import SwiftUI
struct UnwrappingButton<Label: View, T>: View {
enum Unwrapping<T> {
case element(value: T?, action: (T) -> Void)
case binding(value: Binding<T?>, action: (Binding<T>) -> Void)
var value: T? {
switch self {
magnuskahr / View+pulsating.swift
Created Oct 3, 2021
SwiftUI View pulsating effect
View View+pulsating.swift
// View+pulsating.swift
// Created by Magnus Jensen on 02/10/2021.
import SwiftUI
extension View {
func pulsating() -> some View {
magnuskahr / IntegerField.swift
Created Aug 2, 2021
An integer field in swiftui
View IntegerField.swift
struct IntegerField: View {
@Binding var value: Int
@State private var stringValue: String
init(value binding: Binding<Int>) {
self._value = binding
self._stringValue = State(wrappedValue: binding.wrappedValue.formatted())
magnuskahr / AnimateableView.swift
Created May 13, 2021
Rolling animatable view
View AnimateableView.swift
struct AnimateableView<ContentView: View, Value: VectorArithmetic>: View {
let value: Value
@ViewBuilder let builder: (Value) -> ContentView
var body: some View {
.modifier(Animation<ContentView, Value>(value: value, builder: builder))
magnuskahr / EnumPicker.swift
Last active Feb 11, 2022
A simple picker to pick a enum.
View EnumPicker.swift
import SwiftUI
struct EnumPicker<T: Hashable & CaseIterable, V: View>: View {
@Binding var selected: T
var title: String? = nil
let mapping: (T) -> V
var body: some View {
magnuskahr / bingo-python.ipynb
Created Dec 13, 2019
Bingo Ticket Isolation
View bingo-python.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.