Last active
August 29, 2015 14:05
-
-
Save bimawa/29def2eb314faa4c6365 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>IDECodeSnippetCompletionPrefix</key> | |
<string>@weakselfnotnil</string> | |
<key>IDECodeSnippetCompletionScopes</key> | |
<array> | |
<string>CodeExpression</string> | |
</array> | |
<key>IDECodeSnippetContents</key> | |
<string>@weakselfnotnil(^(<#arguments#>)) { | |
<#body#> | |
} @weakselfend</string> | |
<key>IDECodeSnippetIdentifier</key> | |
<string>3D5F0063-0266-40FE-AA0B-C3AB67CE491D</string> | |
<key>IDECodeSnippetLanguage</key> | |
<string>Xcode.SourceCodeLanguage.Objective-C</string> | |
<key>IDECodeSnippetSummary</key> | |
<string>Creates block wrapped to @weakselfnotnil macro</string> | |
<key>IDECodeSnippetTitle</key> | |
<string>Weakselfnotnil block</string> | |
<key>IDECodeSnippetUserSnippet</key> | |
<true/> | |
<key>IDECodeSnippetVersion</key> | |
<integer>2</integer> | |
</dict> | |
</plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>IDECodeSnippetCompletionPrefix</key> | |
<string>@weakself</string> | |
<key>IDECodeSnippetCompletionScopes</key> | |
<array> | |
<string>CodeExpression</string> | |
</array> | |
<key>IDECodeSnippetContents</key> | |
<string>@weakself(^(<#arguments#>)) { | |
<#body#> | |
} @weakselfend</string> | |
<key>IDECodeSnippetIdentifier</key> | |
<string>FFE129E4-54E5-46D0-8454-B37CC620BB2E</string> | |
<key>IDECodeSnippetLanguage</key> | |
<string>Xcode.SourceCodeLanguage.Objective-C</string> | |
<key>IDECodeSnippetSummary</key> | |
<string>Creates block wrapped to @weakself macro</string> | |
<key>IDECodeSnippetTitle</key> | |
<string>Weakself block</string> | |
<key>IDECodeSnippetUserSnippet</key> | |
<true/> | |
<key>IDECodeSnippetVersion</key> | |
<integer>2</integer> | |
</dict> | |
</plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <assert.h> | |
#import <objc/NSObjCRuntime.h> | |
#import <CoreFoundation/CoreFoundation.h> | |
#ifndef DEBUG | |
#define weakself(ARGS) \ | |
"weakself should be called as @weakself" @"" ? \ | |
({ __weak typeof(self) _private_weakSelf = self; \ | |
ARGS { \ | |
__strong typeof(_private_weakSelf) self __attribute__((unused)) = _private_weakSelf; \ | |
return ^ (void) { | |
#define weakselfnotnil(ARGS) \ | |
"weakself should be called as @weakself" @"" ? \ | |
({ __weak typeof(self) _private_weakSelf = self; \ | |
ARGS { \ | |
__strong typeof(_private_weakSelf) self __attribute__((unused)) = _private_weakSelf; \ | |
return ^ (void) { if (self) | |
#else // DEBUG | |
struct RefCountCheckerData { | |
CFTypeRef weakSelf; | |
NSUInteger refCountBefore; | |
}; | |
static inline void vbr_CheckRefCountForWeakSelf(struct RefCountCheckerData *data) { | |
const NSUInteger refCountAfter = (NSUInteger const) CFGetRetainCount(data->weakSelf); | |
const NSUInteger countOfSelfRefInBlock = refCountAfter - data->refCountBefore; | |
assert(countOfSelfRefInBlock == 0); | |
} | |
#define weakself(ARGS) \ | |
"weakself should be called as @weakself" @"" ? \ | |
({ __weak typeof(self) _private_weakSelf = self; \ | |
__attribute__((cleanup(vbr_CheckRefCountForWeakSelf), unused)) \ | |
struct RefCountCheckerData _private_refCountCheckerData = { \ | |
.weakSelf = (__bridge CFTypeRef)self, \ | |
.refCountBefore = CFGetRetainCount((__bridge CFTypeRef)self), \ | |
};\ | |
ARGS { \ | |
__strong typeof(_private_weakSelf) self __attribute__((unused)) = _private_weakSelf; \ | |
return ^ (void) { | |
#define weakselfnotnil(ARGS) \ | |
"weakself should be called as @weakself" @"" ? \ | |
({ __weak typeof(self) _private_weakSelf = self; \ | |
__attribute__((cleanup(vbr_CheckRefCountForWeakSelf), unused)) \ | |
struct RefCountCheckerData _private_refCountCheckerData = { \ | |
.weakSelf = (__bridge CFTypeRef)self, \ | |
.refCountBefore = CFGetRetainCount((__bridge CFTypeRef)self), \ | |
};\ | |
ARGS { \ | |
__strong typeof(_private_weakSelf) self __attribute__((unused)) = _private_weakSelf; \ | |
return ^ (void) { if (self) | |
#endif // DEBUG | |
#define weakselfend \ | |
try {} @finally {} } (); }; \ | |
}) : nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment