0

Is there a way in XCode to find and replace a string either at compile time or automatically?

I am using the DLog Macro

#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#   define DLog(...)
#endif

But sometimes I forget and use NSLog directly, but would want those NSLogs to be changed to DLogs. Would a good solution be to use a build script?

  • Not a direct answer to your question, but you could use this http://stackoverflow.com/questions/16069402/disallow-nslog-to-be-used to "forbid" the usage of NSLog in your source code. – Martin R Jan 11 '14 at 16:32
  • The DLog is a wrapper for NSLog, so I still need to use NSLog in the macro – russellqwerty Jan 11 '14 at 16:47
  • OK, yes of course (I had not noticed that due to the typo in the first version of the question.) - Perhaps one could solve that by defining DLog in terms of an utility functions DLogHelper, but I am not sure if it worth the hassle. – Martin R Jan 11 '14 at 17:33
  • Yea thats my bad on the typo! I was just looking for a quick solution, it might not be worth the hassle – russellqwerty Jan 12 '14 at 13:54

1 Answers1

0

Define following NSLog macro in your .pch(Pre Compiled Header) file to replace iOS SDK's NSLog implementation.

define NSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
ldindu
  • 4,270
  • 2
  • 20
  • 24