Skip to content

Instantly share code, notes, and snippets.

@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
@shaps80
shaps80 / Models.swift
Last active January 9, 2021 16:48
Swift type for representing a UserAgent (includes an implementation similar of Apple’s Version from SPM)
import UIKit
extension UIDevice {
/*
List can be updated here:
https://gist.github.com/adamawolf/3048717
*/
internal static var models: String = """
@steipete
steipete / OSLogStream.swift
Last active November 7, 2023 22:25
Access streaming OSLogStore at runtime with SPI. (FB8519418) https://steipete.com/posts/logging-in-swift/
//
// OSLogStream.swift
// LoggingTest
//
// Created by Peter Steinberger on 24.08.20.
//
// Requires importing https://github.com/apple/llvm-project/blob/apple/master/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h via bridging header
import Foundation
@seanlabastille
seanlabastille / LogReader.swift
Created July 8, 2020 09:47
Attempting to read OSLogStore in iOS 14 Beta 2
import OSLog
class LogReader: ObservableObject {
var log: OSLogStore
init?() {
do {
log = try OSLogStore.init(scope: .currentProcessIdentifier)
dump(log)
/*
@chriseidhof
chriseidhof / boilerplate.swift
Last active January 3, 2024 05:54
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@douglashill
douglashill / MenuAlignment.swift
Last active April 15, 2023 15:45
Swizzles the iOS contextual menu and share sheet to improve usability by showing the icon on the leading side. Read more: https://douglashill.co/menu-icon-swizzling/
// Douglas Hill, March 2020
// Code for the article at https://douglashill.co/menu-icon-swizzling/
import UIKit
struct MenuAlignmentFixError: Error, CustomStringConvertible {
let description: String
}
@IsaacXen
IsaacXen / README.md
Last active May 9, 2024 19:09
(Almost) Every WWDC videos download links for aria2c.
@chriseidhof
chriseidhof / sample.swift
Last active February 25, 2024 16:04
View Inspection
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
zntfdr / firebase-iOS-breakdown.swift
Last active March 27, 2024 15:06
Firebase iOS Version breakdown
// 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 this report” 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
AvdLee / DarwinNotificationCenter.swift
Last active January 23, 2024 07:55
A notification center for Darwin Notifications. MIT License applies.
//
// 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 {