Category: Objective-C

Objective-C
Message Dynamic Resolution: The Complete Execution Flow — Three Chances to Recover

By Seren  |  14 Sep, 2026
1 Comment

I first used Objective-C message forwarding in a production analytics migration, not in a runtime experiment. An older part of the app still sent legacyTrack:payload:, while the replacement service exposed recordEvent:payload:. Rewriting every caller in one release was risky, and silently dropping checkout events was not acceptable. I built a small compatibility layer, then tested […]

Objective-C
AutoreleasePool Creation and Object Release Timing: A Deep Dive

By Seren  |  13 Sep, 2026
Leave a comment

I first paid serious attention to autorelease pools after a data import looked healthy in code review but consumed more memory with every processed file. ARC was enabled, no obvious retain cycle existed, and the final objects were small. The missing piece was the lifetime of thousands of temporary strings and arrays. They were eligible […]

Objective-C
Why Categories Can’t Add Member Variables: Root Cause and Solutions

By Seren  |  12 Sep, 2026
Leave a comment

I learned the limitation of Objective-C categories in a very ordinary way: I added a property to a category, expected the compiler to create storage, and then discovered that no backing instance variable or accessor existed. A category can contribute methods to an existing class, but it cannot enlarge instances of that already-defined class. Once […]

Objective-C
Empty Object Message Sending Mechanism and Crash Prevention

By Seren  |  11 Sep, 2026
Leave a comment

The first time I saw Objective-C code send a message to nil, I expected the application to stop. It did not. The call simply produced an empty result and execution continued. That behavior is useful, but it can also make a failed data load look like a legitimate empty value. The important lesson is not […]

Objective-C
iOS Method Cache Mechanism: What I Learned from Digging into objc_msgSend

By Seren  |  10 Sep, 2026
Leave a comment

While optimizing the launch time of an old project last year, I ran into a weird issue: the same method call sometimes took a few nanoseconds, other times a few microseconds. After days of digging, I finally traced it back to a tiny 16-byte struct inside the Objective-C runtime — the method cache. This article […]

Objective-C
SEL, IMP, Method: The Three Core Elements of Objective-C Runtime — A Deep Dive

By Seren  |  09 Sep, 2026
Leave a comment

SEL, IMP, and Method are the three pillars of Objective-C message-sending system. Understanding how they interact at the Runtime level explains why method calls work the way they do. The names made sense on the surface — Method seems like a method, IMP seems like an implementation, SEL seems like a selector — but what […]

Objective-C
Modifying Method Implementations at Runtime

By Seren  |  08 Sep, 2026
Leave a comment

Changing a method behavior at runtime sounds dangerous, but it is exactly what Method Swizzling does — and it is one of the most powerful debugging and extension tools in the Objective-C toolkit. Later, when I discovered Method Swizzling could swap two methods’ implementations at runtime, I realized that methods are actually dynamic at the […]

Objective-C
Associated Objects Storage Structure and Lifecycle

By Seren  |  07 Sep, 2026
Leave a comment

Categories cannot add member variables — that is a fundamental rule of Objective-C. But associated objects provide a workaround that stores data externally, solving the problem without breaking the language design. Then one day I tried to add a member variable in a Category, and Xcode immediately threw an error. That’s when I realized these […]

Objective-C
Using Runtime to Implement Automatic Archiving and Unarchiving

By Seren  |  06 Sep, 2026
Leave a comment

Writing encodeWithCoder and initWithCoder by hand for every model property is tedious and error-prone. The Runtime offers a way to automate this entirely. If a model had a dozen properties, you’d have to write over a dozen almost identical lines in encodeWithCoder: and initWithCoder:. If you had dozens of models, that was hundreds of lines […]

Objective-C
Traversing All Private Properties and Private Methods in a Class

By Seren  |  05 Sep, 2026
Leave a comment

Every class in Objective-C hides private properties and methods behind its public interface — but with the right Runtime calls, you can expose them all for debugging or introspection..h file was simply inaccessible. Until one day, I tried to modify the placeholder text color of a UITextField. The system clearly had this capability, but it […]