Category: Objective-C
Non-intrusive Function Insertion Based on Runtime
By Seren |
04 Sep, 2026
Leave a comment
Method Swizzling is often called Objective-C black magic, but in practice it is a precise engineering tool — when your product manager asks you to add tracking to 50 ViewControllers without touching any existing code. The product manager’s requirement: every page appearance needed to report data. Adding code to each Controller one by one would […]
Dynamically Creating Classes and Assigning Properties at Runtime
By Seren |
03 Sep, 2026
Leave a comment
Objective-C Runtime lets you create classes entirely at runtime — a capability that powers KVO, Core Data, and many other framework internals that most developers take for granted. The ability to dynamically create classes at runtime is more practical than I’d ever imagined. Why We Need Dynamic Class Creation In conventional development, we define classes […]
Block Internal Function Pointer Structure Parsing
By Seren |
02 Sep, 2026
Leave a comment
Every Block you write is actually a full C struct hiding behind a simple syntax. Understanding this struct — its fields, offsets, and memory layout — is the key to debugging Block-related crashes. It wasn’t until I was debugging a crash and saw __block_invoke everywhere in the stack trace that I realized Blocks are far […]
Block Modify Local Variable Core Implementation Logic
By Seren |
01 Sep, 2026
Leave a comment
Why does adding __block to a variable inside a Block suddenly allow modification? The answer involves a hidden pointer redirect that most tutorials gloss over. The answer lies in Block’s variable capture mechanism and the underlying data structure of __block. The Phenomenon: What Happens Without __block Here’s some basic code: num was 100 when the […]
Objective-C Tagged Pointers Explained: Why Some Objects Never Reach the Heap
By Seren |
30 Aug, 2026
Leave a comment
I ran into tagged pointers through an allocation mystery. A test loop created thousands of boxed numbers, but Instruments showed far fewer heap allocations than I expected. At first I assumed the optimizer had removed my code. The values were definitely being consumed, though, and the count still looked “wrong.” Logging a few object addresses […]
KVO’s Hidden Subclass: How isa-Swizzling Changes Objective-C Objects at Runtime
By Seren |
29 Aug, 2026
Leave a comment
I first noticed KVO’s hidden subclass while debugging a setter breakpoint. The object printed as Person, but the call stack showed a class name I had never created. For a few minutes I wondered whether another library had swizzled the model behind my back. Printing both [object class] and object_getClass(object) before and after adding the […]
Zombie Object Debugging Principle and Usage Skills
By Seren |
15 Aug, 2026
Leave a comment
EXC_BAD_ACCESS crashes are among the most frustrating errors in iOS development. You see a memory address, no stack trace, no hints — just a blank console staring back at you. Later I learned that this crash is usually caused by accessing a deallocated object — a “dangling pointer” problem. And Xcode’s “Zombie Objects” debugging tool […]
MRC and ARC Mixed Compilation Adaptation Rules
By Seren |
13 Aug, 2026
Leave a comment
Mixing ARC and MRC in a single Xcode project sounds like a recipe for disaster, but sometimes it is the only option when inheriting legacy codebases or integrating third-party libraries. Later, when I inherited a legacy project, I discovered it contained a bunch of MRC third-party libraries, and compilation immediately failed. After researching, I learned […]
Stack Block, Heap Block, Global Block Lifecycle Management
By Seren |
10 Aug, 2026
Leave a comment
Blocks in Objective-C come in three distinct flavors — Global, Stack, and Heap — each with its own lifecycle rules and memory behavior that most developers never consciously think about. It wasn’t until I encountered a wild pointer crash under MRC that I realized Blocks have three different forms in memory: Global Blocks, Stack Blocks, […]
Object Property Default Initialization Rules Explained
By Seren |
07 Jul, 2026
Leave a comment
When an Objective-C object is allocated but not yet initialized, its properties default to zero — a behavior rooted in how calloc works, not in any runtime magic. I was nervous — would this crash? It didn’t. The count returned 0. Later I realized this wasn’t luck — it’s because the Objective-C runtime zeroes everything […]
