Skip to content

Instantly share code, notes, and snippets.

View keith's full-sized avatar

Keith Smiley keith

View GitHub Profile
@keith
keith / README.md
Last active January 9, 2024 07:52
A test of `@_dynamicReplacement` in Swift

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 December 7, 2022 23:27
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)
addmedia
addphoto
addvideo
appinfo
boot
bootstatus
clone
create
darwinup
delete
@keith
keith / exclusivity.md
Last active May 6, 2021 00: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
@keith
keith / delete-apps.rb
Last active September 10, 2018 23:39
A script for prompting to delete app ids from the provisioning portal
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 July 20, 2017 07:17
NSDocument canClose in 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 November 1, 2023 12:59
Upload an ipa to testflight using altool
#!/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 October 11, 2016 22:13
Implicitly unwrapped optional crash
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 October 14, 2016 20:07
Swift 3.0 optimizations crash (fixed in Xcode 8.1 beta 3)
///
/// 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 December 22, 2016 13:35
Build to iOS 10 from Xcode 7.3.1

Keybase proof

I hereby claim:

  • I am keith on github.
  • I am smileykeith (https://keybase.io/smileykeith) on keybase.
  • I have a public key whose fingerprint is AC20 B263 327E 9C9A A61A 55A1 33BA 60D4 4C71 67F8

To claim this, I am signing this object: