Skip to content

Instantly share code, notes, and snippets.

@joelekstrom
joelekstrom / SwiftUIDoubleClickModifier.swift
Last active March 11, 2024 12:02
A view modifier that can reliably detect double clicks on macOS, even in List
extension View {
/// Adds a double click handler this view (macOS only)
///
/// Example
/// ```
/// Text("Hello")
/// .onDoubleClick { print("Double click detected") }
/// ```
/// - Parameters:
/// - handler: Block invoked when a double click is detected
@jfuellert
jfuellert / ScrollableView.swift
Last active April 11, 2024 17:57
A scrollable SwiftUI view, UIScrollView wrapper. ScrollableView lets you read and write content offsets for scrollview in SwiftUI, with and without animations.
import SwiftUI
struct ScrollableView<Content: View>: UIViewControllerRepresentable, Equatable {
// MARK: - Coordinator
final class Coordinator: NSObject, UIScrollViewDelegate {
// MARK: - Properties
private let scrollView: UIScrollView
var offset: Binding<CGPoint>
@mecid
mecid / PagerView.swift
Last active December 10, 2023 19:24
PagerView in SwiftUI
//
// PagerView.swift
//
// Created by Majid Jabrayilov on 12/5/19.
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
struct PagerView<Content: View>: View {
let pageCount: Int
@HarshilShah
HarshilShah / UserDefault.swift
Created October 18, 2019 15:23
An observable property wrapper for UserDefaults
import Foundation
import Combine
@propertyWrapper
final class UserDefault<Wrapped>: NSObject, ObservableObject {
typealias Validator = (Wrapped) -> (Wrapped)
private let suite: UserDefaults
private let key: String
struct User: Codable {
var firstName: String
var lastName: String
var lastLogin: Date?
}
@propertyWrapper
struct Storage<T: Codable> {
private let key: String
private let defaultValue: T
//------------------------------------------------------------------------
// The SwiftUI Lab: Advanced SwiftUI Animations
// https://swiftui-lab.com/swiftui-animations-part1 (Animating Paths)
// https://swiftui-lab.com/swiftui-animations-part2 (GeometryEffect)
// https://swiftui-lab.com/swiftui-animations-part3 (AnimatableModifier)
//------------------------------------------------------------------------
import SwiftUI
struct ContentView: View {
@lewislepton
lewislepton / BufferedAudioBus.hpp
Created March 31, 2017 13:25
AudioKit on Audio Unit v3 (extension)
/*
<samplecode>
<abstract>
Utility classes to manage audio formats and buffers for an audio unit implementation's input and output audio busses.
</abstract>
</samplecode>
*/
#import <AudioToolbox/AudioToolbox.h>
#import <AudioUnit/AudioUnit.h>
http://devstreaming.apple.com/videos/wwdc/2016/102w0bsn0ge83qfv7za/102/102_platforms_state_of_the_union.pdf
http://devstreaming.apple.com/videos/wwdc/2016/201h1g4asm31ti2l9n1/201/201_internationalization_best_practices.pdf
http://devstreaming.apple.com/videos/wwdc/2016/202w2zhc4l8yomptqnt/202/202_whats_new_in_accessibility.pdf
http://devstreaming.apple.com/videos/wwdc/2016/203x2w42att1kdzg1ce/203/203_whats_new_in_cocoa.pdf
http://devstreaming.apple.com/videos/wwdc/2016/204t23fvanrkj7a1oj7/204/204_imessage_apps_and_stickers_part_1.pdf
http://devstreaming.apple.com/videos/wwdc/2016/205n2okotvilcayc8rc/205/205_whats_new_in_cocoa_touch.pdf
http://devstreaming.apple.com/videos/wwdc/2016/206a38wgme6uponcuwd/206/206_whats_new_in_tvos.pdf
http://devstreaming.apple.com/videos/wwdc/2016/207i37356qcyyh2yxos/207/207_whats_new_in_foundation_for_swift.pdf
http://devstreaming.apple.com/videos/wwdc/2016/208j30f4v1a1i9i5fg9/208/208_whats_new_in_watchos_3.pdf
http://devstreaming.apple.com/videos/wwdc/2016/209e37d5ks3pfj21ij5/2
@Ridwy
Ridwy / parseRIFF.m
Created May 19, 2012 07:19
Parsing RIFF File
/*
NSDictionary* parseRIFF(NSString* path)
parse RIFF file
General output dictionary
{
formType = {
chunkId = ... ;
@albertodebortoli
albertodebortoli / gist:2602966
Created May 5, 2012 14:39
JSON to NSManagedObject and viceversa (concept)
- (NSString*)jsonStructureFromManagedObjects:(NSArray*)managedObjects;
- (NSArray*)managedObjectsFromJSONStructure:(NSString*)json withManagedObjectContext:(NSManagedObjectContext*)moc;
- (NSDictionary*)dataStructureFromManagedObject:(NSManagedObject*)managedObject
{
NSDictionary *attributesByName = [[managedObject entity] attributesByName];
NSDictionary *relationshipsByName = [[managedObject entity] relationshipsByName];
NSMutableDictionary *valuesDictionary = [[managedObject dictionaryWithValuesForKeys:[attributesByName allKeys]] mutableCopy];
[valuesDictionary setObject:[[managedObject entity] name] forKey:@"ManagedObjectName"];
for (NSString *relationshipName in [relationshipsByName allKeys]) {