惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
D
DataBreaches.Net
雷峰网
雷峰网
WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Engineering at Meta
Engineering at Meta
月光博客
月光博客
V
Visual Studio Blog
美团技术团队
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
博客园 - 【当耐特】
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东

Peter Steinberger

OpenClaw, OpenAI and the future | Peter Steinberger Shipping at Inference-Speed | Peter Steinberger The Signature Flicker | Peter Steinberger Just Talk To It - the no-bs Way of Agentic Engineering | Peter Steinberger Claude Code Anonymous | Peter Steinberger Live Coding Session: Building Arena | Peter Steinberger My Current AI Dev Workflow | Peter Steinberger Essential Reading for Agentic Engineers - August 2025 | Peter Steinberger Just One More Prompt | Peter Steinberger Poltergeist: The Ghost That Keeps Your Builds Fresh | Peter Steinberger Don't read this Startup Slop | Peter Steinberger Essential Reading for Agentic Engineers - July 2025 | Peter Steinberger Self-Hosting AI Models After Claude's Usage Limits | Peter Steinberger Logging Privacy Shenanigans | Peter Steinberger VibeTunnel's first AI-anniversary | Peter Steinberger Making AppleScript Work in macOS CLI Tools: The Undocumented Parts | Peter Steinberger Peekaboo 2.0 – Free the CLI from its MCP shackles | Peter Steinberger Command your Claude Code Army, Reloaded | Peter Steinberger Essential Reading for Agentic Engineers | Peter Steinberger Slot Machines for Programmers: How Peter Builds Apps 20x Faster with AI | Peter Steinberger My AI Workflow for Understanding Any Codebase | Peter Steinberger stats.store: Privacy-First Sparkle Analytics | Peter Steinberger Showing Settings from macOS Menu Bar Items: A 5-Hour Journey | Peter Steinberger VibeTunnel: Turn Any Browser into Your Mac's Terminal | Peter Steinberger Vibe Meter 2.0: Calculating Claude Code Usage with Token Counting | Peter Steinberger llm.codes: Make Apple Docs AI-Readable | Peter Steinberger Automatic Observation Tracking in UIKit and AppKit: The Feature Apple Forgot to Mention | Peter Steinberger Peekaboo MCP – lightning-fast macOS screenshots for AI agents | Peter Steinberger Migrating 700+ Tests to Swift Testing: A Real-World Experience | Peter Steinberger Commanding Your Claude Code Army | Peter Steinberger
InterposeKit — Elegant Swizzling in Swift | Peter Steinbe...
Peter Steinberger · 2020-05-31 · via Peter Steinberger

I built a thing! InterposeKit is a modern library for elegantly swizzling in Swift. It’s on GitHub, fully written in Swift 5.2+, and works on @objc dynamic Swift functions or Objective-C instance methods.

The inspiration for InterposeKit was a race condition in Mac Catalyst, which required some tricky swizzling to fix. With InterposeKit, this is now much cleaner. Since everything’s explained much better on the project website, I’m just writing some random thoughts on building this that didn’t fit into the README.

GitHub Actions

Wow! I didn’t have the time to play with this before, but damn is it 💖 good. GitHub Actions is fast, easy to set up, reliable, and superbly well integrated — all the way down to automatic badges for CI state.

There are a few annoyances, like not being able to run Docker containers on macOS (this isn’t technical, just a money thing). The default Jazzy setup to generate documentation runs via Docker, so I had to jump through some hoops to make my project compile on Linux.

Swift and Type Aliases

It’s extremely unfortunate that the @convention() modifier can’t be used on existing type aliases — this would have made Interpose way more convenient. I’m honestly tempted to write a proposal to get this into Swift because it would be cool and I’d be really interested in the learning experience.

{% twitter https://twitter.com/steipete/status/1266799174563041282 %}

Swift Package Manager

I finally watched WWDC2019:410 Creating Swift Packages and WWDC2019:408 Adopting Swift Packages in Xcode (Hi Boris!) and I really like SwiftPM. Yes, there’s a still a lot to do, but it’s getting Package Resources (SE-0271) with Xcode 12, and the integration with GitHub is nice. Not being allowed to delete DerivedData anymore will be difficult though.

Class Load Events

objc_addLoadImageFunc is a big no-no, and it probably shouldn’t even exist in the header at all. However, there’s _dyld_register_func_for_add_image, which is great. This includes a C callback, and while Swift does a really good job of making it just blend into the language, this callback is not a block and it can’t capture state. I eventually found out that I can put everything into a struct, as long as it’s all static, in order to not have this pollute my global namespace.

Why would I need this? There was a particular bug in Mac Catalyst that required such a trick.

Swift 5.2 callAsFunction

Well well well… here I was bitchin’ about Swift getting useless features, only to be extremely happy about callAsFunction a few months later. In InterposeKit, I use it to have a shorthand for calling the original implementation of a function. It even does generics!

imp_implementationWithBlock

imp_implementationWithBlock has no way to undo or deregister the IMP, so once you submit a block that captures state, you have a permanent memory leak? Oh well.

Closing Thoughts

This is my first Swift-specific open source project, apart from the usual gists. I’d like to learn, so please: BE harsh on me. I had a lot of fun and built this in a weekend. It helped me forget time and space (and current world events) for a bit and just tinker. I’m also sure I got things wrong, so please do tell me what can be made better.