Skip to content

Instantly share code, notes, and snippets.

@Jeehut
Jeehut / SafeLocalizedStringKey.swift
Created July 19, 2020 17:00
Exploring safer localization workflows in SwiftUI ...
// Copyright © 2020 Flinesoft. All rights reserved.
import Foundation
import SwiftUI
public struct SafeLocalizedStringKey :
ExpressibleByStringLiteral,
ExpressibleByStringInterpolation,
ExpressibleByExtendedGraphemeClusterLiteral,
ExpressibleByUnicodeScalarLiteral,
@aheze
aheze / iPadSwiftPlaygrounds_PlayAudio_SwiftUI.swift
Last active May 22, 2021 22:46
How to play custom audio on Swift Playgrounds for iPad, using SwiftUI. Replace "slow-spring-board" with the name of your audio file.
import AVFoundation
import SwiftUI
import PlaygroundSupport
struct SwiftUIAudioPlayerView: View {
/// the audio player that will play your audio file. Can't be a local variable.
/// Must be a `@State` property because we need to modify it later
@State var audioPlayer: AVAudioPlayer?
@avaidyam
avaidyam / BackdropView.swift
Created July 2, 2020 17:23
DIY NSVisualEffectView using Private API for macOS
// TODO: setting window transforms (or mission control) flattens layers...
// TODO: Mask image vs path (layer)?
/// `NSVisualEffectView`:
///
/// A view that adds translucency and vibrancy effects to the views in your interface.
/// When you want views to be more prominent in your interface, place them in a
/// backdrop view. The backdrop view is partially transparent, allowing some of
/// the underlying content to show through. Typically, you use a backdrop view
/// to blur background content, instead of obscuring it completely. It can also
@h4yder
h4yder / CGPointAdditions.swift
Created June 19, 2020 02:09
CGPoint add and multiply extension
extension CGPoint {
static func * (left: CGPoint, scalar: CGFloat) -> CGPoint {
return CGPoint(x: left.x * scalar, y: left.y * scalar)
}
static func * (scalar: CGFloat, right: CGPoint) -> CGPoint {
return CGPoint(x: right.x * scalar, y: right.y * scalar)
}
static func + (left: CGPoint, right: CGPoint) -> CGPoint {
@mecid
mecid / AnimatableVector.swift
Last active July 8, 2025 16:53
High-performance Animatable Vector for SwiftUI
import SwiftUI
import enum Accelerate.vDSP
struct AnimatableVector: VectorArithmetic {
static var zero = AnimatableVector(values: [0.0])
static func + (lhs: AnimatableVector, rhs: AnimatableVector) -> AnimatableVector {
let count = min(lhs.values.count, rhs.values.count)
return AnimatableVector(values: vDSP.add(lhs.values[0..<count], rhs.values[0..<count]))
}
@xtabbas
xtabbas / SnapCarousel.swift
Created May 10, 2020 18:13
A carousel that snap items in place build on top of SwiftUI
//
// SnapCarousel.swift
// prototype5
//
// Created by xtabbas on 5/7/20.
// Copyright © 2020 xtadevs. All rights reserved.
//
import SwiftUI
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
final class SampleCollectionReusableView: UICollectionReusableView {
private let titleLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
@mattt
mattt / UIViewControllerPreview.swift
Last active December 3, 2024 07:42
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
@panoply
panoply / equal-width.md
Last active June 18, 2025 05:37
2 column full width table for github markdown

Equal widths

Github markdown full-width 2 column table.

@Beneboe
Beneboe / how-to-setup-verified-commits.md
Last active July 29, 2025 22:31
How to Setup Verified Commits on Github