explaingit

jspahrsummers/libextobjc

4,505Objective-CAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A modular Objective-C library that adds missing language features, safer memory management macros, defer-style scope cleanup, and compile-time checked key paths, to iOS and macOS codebases.

Mindmap

mindmap
  root((libextobjc))
    What It Does
      Extend Objective-C
      Safer memory patterns
    Key Features
      weakify and strongify
      onExit defer
      Safe categories
    Target Platforms
      iOS
      macOS
    Use Cases
      Retain cycle prevention
      Scope cleanup
      Compile-time safety
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Use @weakify and @strongify in an iOS view controller to safely capture self in completion blocks without creating a retain cycle.

USE CASE 2

Use @onExit to guarantee a mutex is unlocked or a file is closed when a method scope exits, regardless of which return path is taken.

USE CASE 3

Add methods to existing system classes with safe categories that warn at compile time if you accidentally overwrite a built-in method.

Tech stack

Objective-CXcode

Getting it running

Difficulty · easy Time to first run · 5min

Requires Automatic Reference Counting (ARC) to be enabled in your Xcode project.

Use freely in any project, commercial or personal, as long as you keep the copyright notice.

In plain English

libextobjc is a collection of extensions for Objective-C, the programming language historically used to build apps for Apple platforms like iOS and macOS. The library adds language-level features that Objective-C does not include on its own, borrowing patterns from other programming languages to make common tasks safer and more expressive. The most widely used piece is a pair of macros called @weakify and @strongify, which solve a recurring problem in Objective-C code: when you write a block of code that refers to an object, it is easy to accidentally create a retain cycle, where the object and the block each keep each other alive permanently and nothing ever gets freed from memory. These macros make the safe pattern for avoiding that problem much shorter to write. Another popular feature is @onExit, which runs a block of code automatically when the current scope ends, similar to the "defer" keyword in other languages. It is typically used to release memory, unlock mutexes, or close files, regardless of how the scope exits. Other features include safe categories, which let you add methods to existing classes and get a compiler warning if you accidentally overwrite a method that is already there. Concrete protocols let you define default method implementations in a protocol, something Objective-C's protocol system did not natively support before this library. Key path coding adds compile-time checking of key paths, catching typos that would otherwise only surface as runtime crashes. The library is built to be modular: most of its components have only one or two dependencies on other parts, so you can include only the pieces you need rather than the whole library. The project requires ARC (Automatic Reference Counting), a memory management mode in Objective-C. It is released under the MIT License. While Objective-C development has declined in favor of Swift, many existing iOS codebases still use Objective-C, and some of the patterns from this library influenced later Swift standard library designs.

Copy-paste prompts

Prompt 1
Show me how to use libextobjc's @weakify and @strongify macros in an Objective-C UIViewController to safely capture self in a network completion block without creating a retain cycle.
Prompt 2
Using libextobjc's @onExit macro, write an Objective-C method that locks a mutex at the start and guarantees it is unlocked no matter how the method exits.
Prompt 3
How do I use libextobjc's key path coding macros to get a compile-time-checked keyPath string for use with NSFetchRequest in Core Data?
Prompt 4
Show me how to import only the @weakify/@strongify module from libextobjc in a CocoaPods Podfile without pulling in the entire library.
Open on GitHub → Explain another repo

← jspahrsummers on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.