Created
May 25, 2021 03:13
-
-
Save michaeltyson/86236112d0bb9024f4b09cf33056a531 to your computer and use it in GitHub Desktop.
Xcode Build Script phase to check for retain cycles within blocks (self capture)
This file contains 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
#!/bin/sh | |
EXCEPTIONS=( | |
', ' | |
'animations:' | |
'animateChanges:' | |
'changes:' | |
'completion:' | |
'completionBlock:' | |
'CompletionBlock:' | |
'performAnimations:' | |
'performWithoutAnimation:' | |
'performAtomicBatchUpdate:' | |
'performOffscreenRenderWithBlock:' | |
) | |
REGEX="" | |
for exception in "${EXCEPTIONS[@]}"; do | |
REGEX="$REGEX(?<!$(sed 's/[][\.|$(){}?+*^]/\\&/g' <<< "$exception"))" | |
done | |
REGEX=$REGEX'\^\s*\{[.\s]*?self' | |
IFS=$'\n' | |
for line in `pcregrep --line-offsets -H -n --include='\.[mc]' -r -M "$REGEX" . 2>/dev/null`; do | |
echo "$(sed -E 's/(.*):.*/\1/' <<< "$line"): warning: Possible retain cycle" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment