Skip to content

Instantly share code, notes, and snippets.

@ryanlintott
ryanlintott / ContentView.swift
Last active May 13, 2024 07:20
A SwiftUI environment value for the keyboard height that updates with animation. This is useful when you want a specific view in a stack to stick to the bottom of the keyboard when the keyboard moves up.
import SwiftUI
struct ContentView: View {
var body: some View {
KeyboardAvoidingWithOffset()
.keyboardHeightEnvironmentValue()
}
}
struct KeyboardAvoidingWithOffset: View {
@IsaacXen
IsaacXen / README.md
Last active May 17, 2024 21:08
(Almost) Every WWDC videos download links for aria2c.
@nehayward
nehayward / ScanViewController.swift
Created November 18, 2019 23:26
A simple QR code scanner using Vision for iOS (Swift)
import UIKit
import Vision
import AVFoundation
import Foundation
class ScanViewController: UIViewController {
private lazy var cameraPreviewLayer: AVCaptureVideoPreviewLayer = {
let l = AVCaptureVideoPreviewLayer(session: captureSession)
l.videoGravity = .resizeAspectFill
l.connection?.videoOrientation = .portrait
@ole
ole / core-data-backup.swift
Last active January 1, 2024 16:52
How to make a copy of a Core Data SQLite database. See https://oleb.net/blog/2018/03/core-data-sqlite-backup/ for more.
import CoreData
import Foundation
/// Safely copies the specified `NSPersistentStore` to a temporary file.
/// Useful for backups.
///
/// - Parameter index: The index of the persistent store in the coordinator's
/// `persistentStores` array. Passing an index that doesn't exist will trap.
///
/// - Returns: The URL of the backup file, wrapped in a TemporaryFile instance
@ian-mcdowell
ian-mcdowell / DebuggingOverlay.m
Last active February 27, 2021 19:04
UIDebuggingInformationOverlay for iOS 10, 11, and 12
#import <objc/runtime.h>
@interface DebuggingOverlay: NSObject
@end
@implementation DebuggingOverlay
+ (void)toggleOverlay {
id debugInfoClass = NSClassFromString(@"UIDebuggingInformationOverlay");
@eoghain
eoghain / CustomInteractiveAnimationNavigationController.swift
Last active September 21, 2023 07:33
UINavigationController that implements swipe to push/pop in an interactive animation. Just implement the InteractiveNavigation protocol on your ViewControllers you add to the nav stack to get custom transitions. Or implement a single animation and return it instead of the nil's in the UIViewControllerTransitioningDelegate and all transitions wil…
import UIKit
protocol InteractiveNavigation {
var presentAnimation: UIViewControllerAnimatedTransitioning? { get }
var dismissAnimation: UIViewControllerAnimatedTransitioning? { get }
func showNext()
}
enum SwipeDirection: CGFloat, CustomStringConvertible {
@steipete
steipete / SpinlockTestTests.swift
Last active August 29, 2023 08:47 — forked from RomanTruba/Synchronization_test_iOS_SDK10
Updated for Xcode 8, Swift 3; added os_unfair_lock
//
// SpinlockTestTests.swift
// SpinlockTestTests
//
// Created by Peter Steinberger on 04/10/2016.
// Copyright © 2016 PSPDFKit GmbH. All rights reserved.
//
import XCTest
@ypresto
ypresto / YPLayoutGuideHelper.m
Last active April 20, 2020 15:07
Apply automaticallyAdjustsScrollViewInsets in child view controller like Container View or UIPageViewController
//
// YPLayoutGuideHelper.m
//
// Created by Yuya Tanaka, 2015
//
// This is free and unencumbered software released into the public domain.
// Refer: http://unlicense.org/
//
// automaticallyAdjustsScrollViewInsets doesn't work for child view controllers
// hosted by something like Container View or UIPageViewController.
@klundberg
klundberg / weakify.swift
Last active May 13, 2020 08:22
Weakify functions to help you weakly bind instances to static method references
// these functions take a swift class's statically referenced method and the instance those methods
// should apply to, and returns a function that weakly captures the instance so that you don't have
// to worry about memory retain cycles if you want to directly use an instance method as a handler
// for some object, like NSNotificationCenter.
//
// For more information, see this post:
// http://www.klundberg.com/blog/capturing-objects-weakly-in-instance-method-references-in-swift/
func weakify <T: AnyObject, U>(owner: T, f: T->U->()) -> U -> () {
return { [weak owner] obj in
@antonjn
antonjn / find_largest_folders_and_files
Last active August 29, 2015 14:16
Find largest folders and files
du -h / | sort -n | grep -E '^(\d+?| \d+?|\d,\d)G'