Skip to content

Instantly share code, notes, and snippets.

View dezinezync's full-sized avatar
🏠
Working from home

Nikhil Nigade dezinezync

🏠
Working from home
View GitHub Profile
@marioaguzman
marioaguzman / Custom
Last active February 1, 2026 13:51
Creating NSTableView Gradient Header
import AppKit
/// Custom drawing of a Table's Header Row by darkening the background to a light gray rather than just being white.
class GradientTableHeaderCell: NSTableHeaderCell {
/// Light Mode Gradient
var backgroundFillGradient: NSGradient! {
NSGradient(colorsAndLocations:
(NSColor.secondarySystemFill.withAlphaComponent(0.55), 0.0), // Bottom
(NSColor.secondarySystemFill.withAlphaComponent(0.075), 1.0) // Top
import SwiftUI
@main
struct TravelPhotographyApp: App {
var body: some Scene {
WindowGroup {
RootView()
}
.commands {
TextEditingCommands()
@juliensagot
juliensagot / VariableBlurView.swift
Last active September 22, 2025 06:52
SwiftUI variable blur view
import Foundation
import SwiftUI
import UIKit
extension UIBlurEffect {
public static func variableBlurEffect(radius: Double, imageMask: UIImage) -> UIBlurEffect? {
let methodType = (@convention(c) (AnyClass, Selector, Double, UIImage) -> UIBlurEffect).self
let selectorName = ["imageMask:", "effectWithVariableBlurRadius:"].reversed().joined()
let selector = NSSelectorFromString(selectorName)
@phillipcaudell
phillipcaudell / Confirmation.swift
Created September 1, 2023 09:50
Present a confirmation dialogue from a swipeAction, contextMenu or other transient view.
import SwiftUI
/// Describe a potentially destructive action to the user.
///
/// A confirmation describes the action to the user and provides a mechanism for confirming the action in the
/// form of a `Button`. You present a confirmation by calling the environment's confirm action:
///
/// ```swift
/// @Environment(\.confirm) private var confirm
///
@sophiateutschler
sophiateutschler / Color+Lch.swift
Created February 8, 2023 19:31
Lch color space initializer for SwiftUI Color
//
// MIT License
//
// Copyright (c) 2023 Sophiestication Software
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@chriseidhof
chriseidhof / ViewToPDF.swift
Created January 6, 2023 15:46
Image Rendering
import SwiftUI
extension View {
@MainActor
func pdf(size: ProposedViewSize) -> Data {
let renderer = ImageRenderer(content: self)
renderer.proposedSize = size
var pdfData = NSMutableData()
renderer.render { size, render in
var mediaBox = CGRect(origin: .zero, size: size)
@cerupcat
cerupcat / Tappable UIView
Last active January 29, 2022 16:09
Turn any UIView into a tappable button that animates and calls a selector
import Foundation
import UIKit
@propertyWrapper
class Tappable<T: UIView>: NSObject, UIGestureRecognizerDelegate {
// MARK: - Public Properties
public var wrappedValue: T? {
willSet {
removeGesture()
@lukaskubanek
lukaskubanek / Bundle+TestFlight.swift
Last active September 29, 2025 14:26
A code snippet for detecting the TestFlight environment for a macOS app at runtime
/// MIT License
///
/// Copyright (c) 2021 Lukas Kubanek, Structured Path GmbH
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
@samwarnick
samwarnick / migrate.swift
Last active January 25, 2023 16:11
Migrate to app group
// In my core data stack
let container = NSPersistentCloudKitContainer(name: "DataModel")
let storeUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupIdentifier)!.appendingPathComponent("DataModel.sqlite")
// Enable history tracking and remote notifications
guard let description = container.persistentStoreDescriptions.first else {
fatalError("###\(#function): Failed to retrieve a persistent store description.")
}
description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
@bobergj
bobergj / ToolbarItemWithControlValidating.swift
Created December 4, 2020 13:13
ToolbarItemWithControlValidating
// View-based toolbar items do not auto-validate by default, since the toolbar item view may
// be of any type. This subclass validates a toolbar item NSControl view against its action target.
class ToolbarItemWithControlValidating: NSToolbarItem {
override func validate() {
// validate with views view
if let action = self.action {
let validator = NSApp.target(forAction: action, to: self.target, from: self) as AnyObject?
switch validator {
case let validator as NSToolbarItemValidation:
isEnabled = validator.validateToolbarItem(self)