Latest 1.1.4
Homepage https://github.com/Rogaven/ODWeakify
License MIT
Platforms ios 5.0, osx 10.6, watchos 1.0, tvos 9.0, requires ARC
Dependencies ODStringify
Frameworks Foundation
Authors

Build Status
codecov.io
CocoaPods Compatible
Carthage compatible
Platform
Twitter

Usage

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>

od_weakify(self);
self.completionHandler = ^{
    od_strongify(self);
    [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 selfweak) you’ll get a warning.

Installation

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

Podfile

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'
end

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.

Author

Alexey Nazaroff, [email protected]

License

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

Latest podspec

{
    "name": "ODWeakify",
    "version": "1.1.4",
    "summary": "Weakify and strongify wrappers for ObjC",
    "homepage": "https://github.com/Rogaven/ODWeakify",
    "license": {
        "type": "MIT",
        "file": "LICENSE.txt"
    },
    "authors": {
        "Alexey Nazaroff": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Rogaven/ODWeakify.git",
        "tag": "1.1.4"
    },
    "social_media_url": "https://twitter.com/nazarff",
    "platforms": {
        "ios": "5.0",
        "osx": "10.6",
        "watchos": "1.0",
        "tvos": "9.0"
    },
    "requires_arc": true,
    "frameworks": "Foundation",
    "source_files": "src/**/*",
    "public_header_files": "src/include/**/*",
    "dependencies": {
        "ODStringify": []
    },
    "prefix_header_contents": "#ifndef TARGET_OS_IOSn  #define TARGET_OS_IOS TARGET_OS_IPHONEn#endifn#ifndef TARGET_OS_WATCHn  #define TARGET_OS_WATCH 0n#endifn#ifndef TARGET_OS_TVn  #define TARGET_OS_TV 0n#endif"
}

Pin It on Pinterest

Share This