Skip to content

Instantly share code, notes, and snippets.

@michaeltyson
Created May 25, 2021 03:13
Show Gist options
  • Save michaeltyson/86236112d0bb9024f4b09cf33056a531 to your computer and use it in GitHub Desktop.
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)
#!/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