Skip to content

Instantly share code, notes, and snippets.

@dskuza
dskuza / SafariLink.swift
Created January 7, 2024 19:41
SFSafariViewController in SwiftUI
import SwiftUI
#if os(iOS)
import UIKit
struct BranchPickerButton: UIViewRepresentable {
public var title: String = ""
public let producer: () async throws -> [(String, String)]
@Binding public var value: String
@leogdion
leogdion / NSWindowAdaptorModifier.swift
Created August 17, 2023 21:49
Allow SwiftUI to modifier NSWindow
//
// NSWindowAdaptorModifier.swift
// Copyright (c) 2023 BrightDigit.
//
import AppKit
import Foundation
import SwiftUI
// swiftlint:disable strict_fileprivate
c: command
cc: commandContext
v: version
P: payload
N: bulkedPayload
fP: fanoutPayload
aP: additionalPayload
Pm: payloadMetadata
i: messageId
U: messageUUID
@marcoarment
marcoarment / Text+InlineSymbol.swift
Last active October 26, 2023 17:13
SwiftUI Text with inline SF Symbols
import SwiftUI
extension Text {
public struct InlineSymbol {
public let name: String
public let accessibilityLabel: String
public let color: Color?
public init(name: String, accessibilityLabel: String, color: Color? = nil) {
self.name = name
@chockenberry
chockenberry / finder_icons.sh
Created March 16, 2023 20:00
Script to toggle Finder icons
#!/bin/sh
defaults read com.apple.finder CreateDesktop > /dev/null 2>&1
enabled=$?
if [ "$1" = "off" ]; then
if [ $enabled -eq 1 ]; then
osascript -e 'tell application "Finder" to quit'
defaults write com.apple.finder CreateDesktop false
open -a Finder
@macshome
macshome / swift-format-defaults.md
Last active October 30, 2023 17:27
The default settings for swift-format

swift-format Default Settings

Since I've not found anywhere that describes the default settings of swift-format other than the code, I've pulled those settings out and presented them here.

Rules that are opt-in are marked as such.

Formating-Only Rules

(Most of these rules are defined in the default config, not the rules folder.)

  1. maximumBlankLines = 1
  2. lineLength = 100
  3. tabWidth = 8
@nicklockwood
nicklockwood / OSKit.swift
Created January 28, 2023 11:32
A lightweight approach to writing cross-platform code in SwiftUI without a lot of conditional compilation blocks
import SwiftUI
enum OSDocumentError: Error {
case unknownFileFormat
}
#if canImport(UIKit)
import UIKit
@UnderscoreDavidSmith
UnderscoreDavidSmith / Sparkle.swift
Created December 20, 2022 16:00
Sparkle Effect in SwiftUI
@available(iOS 15.0, *)
struct TwinkleView:View {
private func position(in proxy: GeometryProxy, sparkle:Sparkle) -> CGPoint {
let radius = min(proxy.size.width, proxy.size.height) / 2.0
let drawnRadius = (radius - 5) * sparkle.position.x
let angle = Double.pi * 2.0 * sparkle.position.y
let x = proxy.size.width * 0.5 + drawnRadius * cos(angle)
let y = proxy.size.height * 0.5 + drawnRadius * sin(angle)
struct ContentView: View {
@State var atTop = true
@Namespace var ns
var body: some View {
VStack {
VStack {
Text("Top")
.border(.green)
.opacity(atTop ? 1 : 0)