How do I disable NSLog?

前端 未结 15 2096
陌清茗
陌清茗 2020-12-05 07:46

I\'d like to do the following in Xcode:

Find all NSLog commands without comments, and replace it with //NSLog...

In other words, I want to comment all NSLog

相关标签:
15条回答
  • 2020-12-05 08:18

    I have to do a separate answer because I cant comment yet, but one thing you really need to be careful about when you do a find and replace is something like this:

    if(BOOL)
    NSLog(@"blah blah");
    
    [self doSomething];
    

    If you comment out the nslog, the conditional gets associated with the method below it, correct me if I'm wrong

    0 讨论(0)
  • 2020-12-05 08:20

    Update:

    The answer bellow is actually much better. See here.

    Initial answer:

    There is a little hack that you could do. Search for all NSLog and replace them with //NSLog and than do another search for ////NSLog and replace them with //NSLog.

    0 讨论(0)
  • 2020-12-05 08:24

    in the Menu bar : Edit > Find > Find and Replace in Workspace then, display options to use regular expressions. search/replace for "[^/]NSLog"

    0 讨论(0)
  • 2020-12-05 08:24

    How to disable NSLog in Xcode for Production stage

    Add #define NSLog in appName-Prefix.pch file in Supporting Files Folder of your project and result file code look like...

    // Prefix header for all source files of the 'NSLog' target in the 'NSLog' project
    //
    
    #import <Availability.h>
    
    #ifndef __IPHONE_4_0
    #warning "This project uses features only available in iOS SDK 4.0 and later."
    #endif
    
    #ifdef __OBJC__
        #import <UIKit/UIKit.h>
        #import <Foundation/Foundation.h>
    #endif
    
    //Add this to disable NSLog
    #define NSLog //
    
    0 讨论(0)
  • 2020-12-05 08:26
    #define NSLog if(1) NSLog
    

    if you dont want log set 1 as 0.

    0 讨论(0)
  • 2020-12-05 08:27

    #define NSLog(...)

    add this line into your .pch file

    if you want log than comment it

    0 讨论(0)
提交回复
热议问题