Fancy header-only weakifying and strongifying for Objective-C 💪

What's New

1.1.5 Update import as module



Build Status codecov.io CocoaPods Compatible Carthage compatible Platform Twitter


Do you often write smthng like this in ObjC?

__weak __typeof(self) weakSelf = self;
self.completionHandler = ^{
    __typeof(self) strongSelf = weakSelf;
    [strongSelf doSomething];

    // or just use weakSelf
    weakSelf.var = nil;
    // some other code
    self.property = @"foo";

It looks horrible. And, did you notice, we forgot to use weakSelf when set foo. It's really often mistake. So, with ODWeakify you can do it easier:

// #import <ODWeakify.h>

self.completionHandler = ^{
    [self doSomething];

    self_weak_.var = nil; // We can still use weak if we need it 
    self.property = @"foo";  

Now all selfs inside block will be in safe from retain cycles. And if you forget strongify (and won't use self_weak_) you'll get a warning.


ODWeakify supports multiple methods for installing the library in a project.

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C and Swift, which automates and simplifies the process of using 3rd-party libraries like ODWeakify in your projects. You can install it with the following command:

$ gem install cocoapods


To integrate ODWeakify into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target 'TargetName' do
pod 'ODWeakify'

Then, run the following command:

$ pod install

Installation with Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate ODWeakify into your Xcode project using Carthage, specify it in your Cartfile:

github "Rogaven/ODWeakify" ~> 1.1

Run carthage to build the framework and drag the built ODWeakify.framework into your Xcode project.


Alexey Nazarov, alexx.nazaroff@gmail.com


ODWeakify is available under the MIT license. See the LICENSE file for more info.


  • Swift Tools
View More Packages from this Author


  • None
Last updated: Sat Nov 11 2023 12:34:31 GMT-1000 (Hawaii-Aleutian Standard Time)