Skip to content

Instantly share code, notes, and snippets.

View MarvinNazari's full-sized avatar

Marvin Nazari MarvinNazari

View GitHub Profile
@geraldWilliam
geraldWilliam / Zoom.swift
Last active October 22, 2023 10:16
SwiftUI Zoom
import SwiftUI
struct Zoom: ViewModifier {
@Binding var scale: CGFloat
@Binding var position: CGPoint
@State private var currentZoom: CGFloat = 0
private let scrollCoordinateSpace = "scroll"
@ole
ole / thirty-days-of-metal.md
Last active March 16, 2026 23:16
Warren Moore – Thirty Days of Metal
@ole
ole / RelativeSizeLayout.swift
Last active July 30, 2025 12:15
A SwiftUI layout and modifier for working with relative sizes ("50 % of your container"). https://oleb.net/2023/swiftui-relative-size/
import SwiftUI
extension View {
/// Proposes a percentage of its received proposed size to `self`.
///
/// This modifier multiplies the proposed size it receives from its parent
/// with the given factors for width and height.
///
/// If the parent proposes `nil` or `.infinity` to us in any dimension,
/// we’ll forward these values to our child view unchanged.
@Sherlouk
Sherlouk / DebugDevice.swift
Last active June 9, 2025 15:02
Debug Profiles - Securely debugging in production
//
// DebugDevice.swift
//
// Copyright 2022 • Sidetrack Tech Limited
//
import Foundation
// This must be called on the main-thread.
var isDebugProfileInstalled: Bool {
extension Image {
/// This helps achieving what `UIView.ContentMode.scaleAspectFit` and `.scaleAspectFill` do in UIImageView.contentMode
///
/// The difference between Image.containerAspectRatio (this) and SwiftUIs View.aspectRatio is that the first applies the
/// aspect ratio to the view that contains the image, rather than to the image itself.
///
/// So in the following example:
/// - The first image will scale to a square but the contentMode does not do anything to prevent stretching and wether you use .fit or .fill does not matter.
/// - The second image will resize to fit inside a square while maintaining its aspect ratio, similar to how a UIImageView with contentMode set to scaleAspectFit behaves.
/// - The third image will resize to fill inside a square while maintaining its aspect ratio similar to how a UIImageView with contentMode set to scaleAspectFill behaves.
@dejager
dejager / RoundedPolygon.swift
Created October 18, 2022 05:57
A SwiftUI Shape that draws a polygon with a given number of corners and a corner radius.
//
// RoundedPolygon.swift
//
// Created by Nate on 2022-10-17.
//
import SwiftUI
struct RoundedPolygon: Shape {
extension AsyncSequence where Element: Hashable {
/// Sequence that emits unique elements once each
func unique() -> AsyncUniqueSequence<Self> {
AsyncUniqueSequence(self)
}
}
/// Sequence that only emits unique elements once.
/// While iterating, all emitted elements are retained within a `Set` to ensure uniqueness of each element emitted.
@niaeashes
niaeashes / DebugJsonView.swift
Last active March 15, 2024 05:57
SwiftUI JSON View for Debugging
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct DebugJsonView: View {
let json: JsonElement
init(_ json: String) {
self.json = JsonElement.parse(json)
@bjhomer
bjhomer / cross-view-lines.swift
Last active February 23, 2026 21:27
Creating cross-view lines in SwiftUI
//
// ContentView.swift
// SwiftUIPlayground
//
// Created by BJ Homer on 4/26/21.
//
import SwiftUI
import UIKit
import AVFoundation
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let tableView = UITableView(frame: .zero, style: .plain)
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(PlayerTableViewCell.self, forCellReuseIdentifier: "PlayerCell")