SHARE
TWEET

Untitled

a guest Jan 12th, 2017 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. folder="$1"
  4. if [[ -z "${folder// }" ]]
  5.   then folder=".";
  6. fi
  7.  
  8. echo "Searching through folder \"$folder\" for NotificationCenter observers."
  9. echo ""
  10.  
  11. # Swift files
  12. nbrSwiftFiles=$(grep -l -r "NotificationCenter\.default\.addObserver(forName" $folder \
  13.   | while read -r filename; do echo ${filename// /\\ } ; done \
  14.   | wc -l | tr -d ' ')
  15. echo "Number Swift files: $nbrSwiftFiles"
  16.  
  17. # Objective-C files
  18. nbrObjcFiles=$(grep -l -r "\[\[NSNotificationCenter defaultCenter\] addObserverForName" $folder \
  19.   | while read -r filename; do echo ${filename// /\\ } ; done \
  20.   | wc -l | tr -d ' ')
  21. echo "Number Objective-C files: $nbrObjcFiles"
  22.  
  23. echo ""
  24. echo "  Files without \"removeObserver\" anywhere in the file:"
  25.  
  26. # Swift files
  27. grep -l -r "NotificationCenter\.default\.addObserver(forName" $folder \
  28.   | while read -r filename; do echo ${filename// /\\ } ; done \
  29.   | xargs grep -L "NotificationCenter\.default\.removeObserver"
  30. # Objective-C files
  31. grep -l -r "\[\[NSNotificationCenter defaultCenter\] addObserverForName" $folder \
  32.   | while read -r filename; do echo ${filename// /\\ } ; done \
  33.   | xargs grep -L "\[\[NSNotificationCenter defaultCenter\] removeObserver"
  34.  
  35. echo ""
  36. echo "  Files without \"deinit/dealloc\":"
  37.  
  38. # Swift files
  39. grep -l -r "NotificationCenter\.default\.addObserver(forName" $folder \
  40.   | while read -r filename; do echo ${filename// /\\ } ; done \
  41.   | xargs grep -L "deinit"
  42.  
  43. # Objective-C files
  44. grep -l -r "\[\[NSNotificationCenter defaultCenter\] addObserverForName" $folder \
  45.   | while read -r filename; do echo ${filename// /\\ } ; done \
  46.   | xargs grep -L "dealloc"
RAW Paste Data
Top