Skip to content

Instantly share code, notes, and snippets.

@thelinuxkid
Last active December 12, 2016 03:29
Show Gist options
  • Save thelinuxkid/13dc50b809c71db849c83b668a6bc754 to your computer and use it in GitHub Desktop.
Save thelinuxkid/13dc50b809c71db849c83b668a6bc754 to your computer and use it in GitHub Desktop.
Enable dynamic method lookup for New Relic in Swift
#!/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