Skip to content

Instantly share code, notes, and snippets.

View zoejessica's full-sized avatar
🐗

Zoë Smith zoejessica

🐗
View GitHub Profile
final class Loader: BindableObject {
let didChange = PassthroughSubject<Data?, Never>()
var task: URLSessionDataTask!
var data: Data? = nil {
didSet {
didChange.send(data)
}
}
init(_ url: URL) {
@keith
keith / exclusivity.md
Last active January 11, 2025 03:47
The matrix of Xcode build settings to compiler flags for Swift memory exclusivity
  • Compiler flag: -enforce-exclusivity=<value>
  • Build setting: SWIFT_ENFORCE_EXCLUSIVE_ACCESS

Xcode 10.1 & Swift 4.2

  • Compiler default for non optimized builds if you pass no argument is the same as if you passed checked
  • Compiler default for optimized builds if you pass no argument is the same as if you passed unchecked
Configuration Compiler Flag Value Build Setting Description Build Setting Value Notes
@nicklockwood
nicklockwood / Withable.swift
Created January 28, 2019 12:06
Withable.swift
/// Withable is a simple protocol to make constructing
/// and modifying objects with multiple properties
/// more pleasant (functional, chainable, point-free)
public protocol Withable {
init()
}
public extension Withable {
/// Construct a new instance, setting an arbitrary subset of properties
init(with config: (inout Self) -> Void) {
//
// ThrottleUnlessChanged.swift
//
// Created by Daniel Tartaglia on 6 Jan 2019.
// Copyright © 2020 Daniel Tartaglia. MIT License.
//
import RxSwift
public extension ObservableType where Element: Equatable {
@parrots
parrots / AsyncOperation.swift
Last active May 17, 2021 10:44
A Swifty version of an AsyncOperation which solves two common problems I ran into. (see comment below for issues addressed)
//
// AsyncOperation.swift
// Slopes
//
import Foundation
class AsyncOperation: Operation {
private let stateLock = NSLock()
private var observers: [NSKeyValueObservation] = [NSKeyValueObservation]()
@pepasflo
pepasflo / .gitignore
Last active October 22, 2023 12:06
Scripts for encrypting / decrypting secrets (to prevent them from being accidentally checked into git)
secrets/
@pmatanyc
pmatanyc / StickyHeaderScrollToSection
Created October 22, 2018 14:06
Scrolling to a section with a sticky header in UICollectionView
func scrollToSection(_ section: Int) {
if let collectionView = collectionView {
let indexPath = IndexPath(item: 0, section: section)
if
let attributes = collectionView.layoutAttributesForItem(at: indexPath),
let flowLayout = collectionView.collectionViewLayout as? FlowLayout
{
let headerHeight = flowLayout.headerReferenceSize
let topSectionInset = flowLayout.sectionInset.top
@cellularmitosis
cellularmitosis / EmojiPointersDemo.swift
Created August 15, 2018 18:11
Representing pointer values as emoji can be useful for "visually" debugging certain issues, like cell reuse, etc.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
@CodaFi
CodaFi / MBE.swift
Created July 8, 2018 06:33
Macro-by-Example: Deriving Syntactic Transformations from their Specifications, Re-Typeset
//: Foreword
//:
//: This playground is the culmination of a week of digging around
//: for the oldest papers I could find about (Lisp) macros and their evolution.
//: I found this paper particularly enlightening as it is the place where Scheme
//: and Rust-style "Macro-by-Example" macros first came into their own. In
//: addition, this paper discusses the implementation challenges faced by
//: previous macro systems and Kohlbecker's first go at MBEs.
//:
//: I have re-typeset this paper because [the one hosted by IU](ftp://www.cs.indiana.edu/pub/techreports/TR206.pdf)
@iccir
iccir / SemanticColors.txt
Last active February 27, 2019 19:57
macOS Semantic Colors
Note:
1) These may change in future versions of macOS.
2) Apple may also add more appearances or control accent colors in the future.
3) You probably don't want to hardcode color values.
4) Watch:
https://developer.apple.com/videos/play/wwdc2018/210
https://developer.apple.com/videos/play/wwdc2018/218
All colors specified in the sRGB color space.