Last active
December 12, 2016 03:29
-
-
Save thelinuxkid/13dc50b809c71db849c83b668a6bc754 to your computer and use it in GitHub Desktop.
Enable dynamic method lookup for New Relic in Swift
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/bash | |
# Enable dynamic method lookup for Swift as explained here: | |
# https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-ios/install-configure/enabling-swift-interaction-traces | |
srcdir="$1" | |
if [ -z "$srcdir" ]; then | |
echo Please provide a source directory; | |
exit 1; | |
fi | |
methods=( | |
# UIViewController | |
viewDidLoad | |
viewWillAppear | |
viewDidAppear | |
viewWillDisappear | |
viewDidDisappear | |
viewWillLayoutSubviews | |
viewDidLayoutSubviews | |
# UIImage | |
imageNamed | |
imageWithContentsOfFile | |
imageWithData | |
initWithContentsOfFile | |
initWithData | |
# TODO these are in addition to the above UIImage methods | |
# imageWithData:scale | |
# initWithData:scale | |
# NSJSONSerialization | |
JSONObjectWithData | |
JSONObjectWithStream | |
dataWithJSONObject | |
writeJSONObject | |
# TODO these should replace all the above NSJSONSerialization methods | |
# JSONObjectWithData:options:error | |
# JSONObjectWithStream:options:error | |
# dataWithJSONObject:options:error | |
# writeJSONObject:toStream:options:error | |
# NSManagedObjectContext | |
executeFetchRequest | |
processPendingChanges | |
# TODO these should replace all the above NSManagedObjectContext methods | |
# executeFetchRequest:error | |
) | |
for method in "${methods[@]}"; do | |
old="override func $method" | |
new="override dynamic func $method" | |
grep --color -lIrs "$old" "$srcdir" | xargs -I {} sed -i "" "s/$old/$new/g" {} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment