Skip to content

Instantly share code, notes, and snippets.

@DougGregor
DougGregor / macros.md
Last active October 24, 2023 16:42
A possible vision for macros in Swift

A Possible Vision for Macros in Swift

As Swift evolves, it gains new language features and capabilities. There are different categories of features: some fill in gaps, taking existing syntax that is not permitted and giving it a semantics that fit well with the existing language, with features like conditional conformance or allowing existential values for protocols with Self or associated type requirements. Others introduce new capabilities or paradigms to the language, such as the addition of concurrency or comprehensive reflection.

There is another large category of language features that provide syntactic sugar to eliminate common boilerplate, taking something that can be written out in long-form and making it more concise. Such features don't technically add any expressive power to the language, because you can always write the long-form version, but their effect can be transformational if it enables use cases that would otherwise have been unwieldy. The synthesis of Codable conformances, for ex

@pofat
pofat / Kind.swift
Created March 12, 2021 15:49
Swift Struct Metadata
// Kind of type
public enum Kind {
case `struct`
case `enum`
case optional
case opaque
case tuple
case function
case existential
case metatype
@xsleonard
xsleonard / UUID+Extensions.swift
Created August 26, 2020 06:51
Swift: Convert UUID to and from Data and Int64
extension UUID {
// UUID is 128-bit, we need two 64-bit values to represent it
var integers: (Int64, Int64) {
var a: UInt64 = 0
a |= UInt64(self.uuid.0)
a |= UInt64(self.uuid.1) << 8
a |= UInt64(self.uuid.2) << (8 * 2)
a |= UInt64(self.uuid.3) << (8 * 3)
a |= UInt64(self.uuid.4) << (8 * 4)
a |= UInt64(self.uuid.5) << (8 * 5)
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active May 2, 2024 06:57
set -e, -u, -o, -x pipefail explanation
@steipete
steipete / ios-xcode-device-support.sh
Last active December 12, 2023 03:36
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
@nomeyer
nomeyer / create_app_from_pid.m
Last active September 4, 2021 18:05
Create an app reference from a PID (accessibility)
#include <CoreFoundation/CoreFoundation.h>
AXUIElementRef app = AXUIElementCreateApplication(pid);
@Zenexer
Zenexer / Mac Keyboard Symbols.md
Last active April 6, 2024 07:40
List of Mac/Apple keyboard symbols