https://github.com/nzrsky/odweakify
Fancy header-only weakifying and strongifying for Objective-C 💪
https://github.com/nzrsky/odweakify
cocoa cocoapods ios macos objc objective-c osx weak
Last synced: 9 months ago
JSON representation
Fancy header-only weakifying and strongifying for Objective-C 💪
- Host: GitHub
- URL: https://github.com/nzrsky/odweakify
- Owner: nzrsky
- License: mit
- Archived: true
- Created: 2016-06-14T22:24:43.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-10-22T12:12:24.000Z (over 3 years ago)
- Last Synced: 2025-07-12T08:02:01.736Z (9 months ago)
- Topics: cocoa, cocoapods, ios, macos, objc, objective-c, osx, weak
- Language: C
- Homepage:
- Size: 24.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ODWeakify
[](https://app.travis-ci.com/nzrsky/ODWeakify)
[](https://codecov.io/github/nzrsky/ODWeakify?branch=master)
[](https://cocoapods.org/pods/ODWeakify)
[](https://github.com/Carthage/Carthage)
[](http://cocoadocs.org/docsets/ODWeakify)
[](http://twitter.com/nzrsky)
## Usage
Do you often write smthng like this in ObjC?
```objective-c
__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:
```objective-c
// #import
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 `self`s 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.
## Installation
ODWeakify supports multiple methods for installing the library in a project.
## Installation with CocoaPods
[CocoaPods](http://cocoapods.org) 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:
```bash
$ gem install cocoapods
```
#### Podfile
To integrate ODWeakify into your Xcode project using CocoaPods, specify it in your `Podfile`:
```ruby
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'TargetName' do
pod 'ODWeakify'
end
```
Then, run the following command:
```bash
$ pod install
```
### Installation with Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with [Homebrew](http://brew.sh/) using the following command:
```bash
$ brew update
$ brew install carthage
```
To integrate ODWeakify into your Xcode project using Carthage, specify it in your `Cartfile`:
```ogdl
github "Rogaven/ODWeakify" ~> 1.1
```
Run `carthage` to build the framework and drag the built `ODWeakify.framework` into your Xcode project.
## Author
Alexey Nazarov, alexx.nazaroff@gmail.com
## License
ODWeakify is available under the MIT license. See the LICENSE file for more info.