Skip to content

Instantly share code, notes, and snippets.

@keith
keith / README.md
Last active Oct 28, 2021
A test of `@_dynamicReplacement` in Swift
View README.md

Usage

  1. swiftc main.swift -emit-module-path main.swiftmodule -emit-executable -enable-private-imports -Xfrontend -enable-implicit-dynamic
  2. ./main -> prints From original bar()
  3. swiftc -emit-library inject.swift -o inject.dylib -I . -Xlinker -undefined -Xlinker suppress -Xlinker -flat_namespace -Xfrontend -disable-access-control
  4. DYLD_INSERT_LIBRARIES=inject.dylib ./main -> prints From replacement bar()

Notes

  • Passing -Xfrontend -enable-implicit-dynamic removes you from having to add dynamic to everything you want to be replacable
@keith
keith / simctl-commands.txt
Last active Sep 12, 2021
All the subcommands of `xcrun simctl` (including ones that aren't listed in `simctl help`) LC_SOURCE_VERSION 776.1 (Xcode 13.0 beta 5)
View simctl-commands.txt
addmedia
addphoto
addvideo
appinfo
boot
bootstatus
clone
create
darwinup
delete
@keith
keith / exclusivity.md
Last active May 6, 2021
The matrix of Xcode build settings to compiler flags for Swift memory exclusivity
View exclusivity.md
  • 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
@keith
keith / delete-apps.rb
Last active Sep 10, 2018
A script for prompting to delete app ids from the provisioning portal
View delete-apps.rb
require 'spaceship'
Spaceship::Portal.login
Spaceship::Portal.select_team
Spaceship::Portal.app.all.collect do |app|
print "Delete #{ app.bundle_id }? [y/N]: "
delete = gets.strip.downcase == "y"
if delete
puts "Deleting #{ app.bundle_id }"
@keith
keith / RadarDocument.swift
Created Jul 20, 2017
NSDocument canClose in Swift
View RadarDocument.swift
/// So, lets talk about AppKit. The way this function works is by passing a delegate (which is required
/// to be a NSObject, but here is typed as Any) which turns out to be the same type as `self`, a Selector,
/// which in this case is `_something:didSomething:soContinue:` (not kidding), and some "contextInfo"
/// (which is actually a block). While all of these arguments appear to be optional, passing nil through
/// to the function call that `shouldCloseSelector` defines, or passing nil to super, will cause the app
/// to crash. So then we need to call the function on `delegate` defined by `shouldCloseSelector`.
///
/// According to the documentation the function signature for this selector looks like this:
/// - (void)document:(NSDocument *)doc shouldClose:(BOOL)shouldClose contextInfo:(void *)contextInfo
///
@keith
keith / testflight.sh
Last active Nov 8, 2021
Upload an ipa to testflight using altool
View testflight.sh
#!/bin/bash
set -euo pipefail
xcrun altool --upload-app --type ios --file "path/to/foo.ipa" --username "$ITC_USER" --password "$ITC_PASSWORD"
@keith
keith / userdefaults.swift
Last active Oct 11, 2016
Implicitly unwrapped optional crash
View userdefaults.swift
import Foundation
func set<T>(value: T, forKey key: String) {
UserDefaults.standard.set(value, forKey: key) // this crashes because it's trying to store Optional<Date>
}
let date: Date! = Date()
set(value: date, forKey: "key")
@keith
keith / optimizationCrash.swift
Last active Oct 14, 2016
Swift 3.0 optimizations crash (fixed in Xcode 8.1 beta 3)
View optimizationCrash.swift
///
/// This code crashes with Swift 3.0 with optimizations enabled
/// Run with:
/// $ swift -O optimizationCrash.swift
///
extension Dictionary {
// init(pairs: [(Key, Value)]?) { // With `(Key, Value)` this doesn't crash
init(pairs: [Element]?) { // With `Element` this crashes with -0
self.init()
}
@keith
keith / link.sh
Last active Dec 22, 2016
Build to iOS 10 from Xcode 7.3.1
View link.sh
@keith
keith / lumail2.rb
Created May 28, 2016
Homebrew formula for lumail2
View lumail2.rb
class Lumail2 < Formula
desc "Console based email"
homepage "https://lumail.org/"
url "https://lumail.org/download/lumail-2.5.tar.gz"
version "2.5"
sha256 "76805e40038e11aa3a44fc29a015ca67553b44b7b951839e9f9102679f112c77"
depends_on "pkg-config"
depends_on "pcre++"
depends_on "gmime"