Skip to content

Instantly share code, notes, and snippets.

chriseidhof / sample.swift
Last active Oct 16, 2021
View Inspection
View sample.swift
import SwiftUI
struct SizeKey: PreferenceKey {
static func reduce(value: inout CGSize?, nextValue: () -> CGSize?) {
value = value ?? nextValue()
struct ContentView: View {
@State var width: CGFloat? = nil
var body: some View {
zntfdr / firebase-iOS-breakdown.swift
Last active Nov 30, 2021
Firebase iOS Version breakdown
View firebase-iOS-breakdown.swift
// How to:
// 1. Open the Firebase Analytics Dashboard
// 2. Scroll to bottom, where you see the "Users by Device model" widget
// 3. Click "View device models" in that widget (this opens the "Tech details" Firebase Analytics page)
// 4. Above the table shown in the new page, click on the “Device model” drop down menu and select “OS with Version”
// 5. Make sure to select “OS with version” and not “OS Version”
// 6. On the top right corner of the page, click on the “Share comparison” icon (next to the date)
// 7. Click “Download file” on the new side bar, then “Download CSV"
// 8. Open the file and select the iOS/Android breakdown raw data
// 9. Replace the sample data in this script with your data
AvdLee / DarwinNotificationCenter.swift
Last active Jul 29, 2021
A notification center for Darwin Notifications. MIT License applies.
View DarwinNotificationCenter.swift
// DarwinNotificationCenter.swift
// Copyright © 2017 WeTransfer. All rights reserved.
import Foundation
/// A Darwin notification payload. It does not contain any userInfo, a Darwin notification is purely event handling.
public struct DarwinNotification {
johnno1962 / swiftui.swift
Last active Nov 6, 2019
SwiftUI Injection
View swiftui.swift
// First, install from the Mac AppStore
// Make these changes to your code:
// add the following to application(didFinishLaunchingWithOptions:)
Bundle(path: "/Applications/")?.load()

slidenumber: true autoscale: true

iOS13とmacOS CatalinaのWebSocketサポート


WWDCゴリゴリキャッチアップ会 2019


drewmccormack / LetTheCoWGo.swift
Created Feb 2, 2019
Demonstrates how a Swift value constant can mutate when using Copy-on-Write (CoW) and multi-threading.
View LetTheCoWGo.swift
import Foundation
struct NuclearPowerStationOperator {
class Storage {
var turnOffCores: Bool = false
func copy() -> Storage {
let new = Storage()
new.turnOffCores = turnOffCores
return new
kastiglione / helpers.swift
Last active Nov 13, 2021
Swift helpers, and the lldb setup to use them. Presented @ SLUG
View helpers.swift
extension UIView {
/// Example: call someView.nudge(0, 30)
func nudge(_ dx: CGFloat, _ dy: CGFloat) {
self.frame = self.frame.offsetBy(dx: dx, dy: dy)
extension UIView {
/// Example: po UIView.root
AvdLee / MutableProgress.swift
Last active Nov 18, 2020
Adding children to a Progress instance is easy, but removing is not possible by default. This could have been useful when you want to use a single Progress instance which can have different children over time. Using this custom class MutableProgress makes this possible. See:
View MutableProgress.swift
import UIKit
/// An additional class build on top of `Progress` to make it possible to also remove children from progress.
public final class MutableProgress: Progress {
public override var totalUnitCount: Int64 {
get {
return Int64(children.count)
set {
tclementdev /
Last active Dec 1, 2021
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

milseman /
Created Jan 10, 2018
State of String: ABI, Performance, Ergonomics, and You!

State of String: ABI, Performance, Ergonomics, and You!

Hello, I’ve been working on implementing, optimizing, and improving String in preparation for ABI stability, and I thought I’d share the current status of String in Swift 5 and some potential directions to go. This is the product of conversations with open source contributors and my colleagues on the Swift standard library team at Apple.

The primary area of focus is stabilizing String’s ABI, but we’d be remiss if we couldn’t also fit in performance and ergonomic improvements. String’s ergonomics in particular is one area where we think the status quo is woefully inadequate, and over half of this email is devoted to that topic. At the end, there’s a section about a community initiative that we hope can help users of String as well as guide future development.

(Note: I’m sending this to swift-dev because much of the contents revolve around implementation concerns. I’ll also cross-reference on swift-evolution and swift-users. See also the [StringManife