Custom NSLog for release and debugging, custom nslog debugging

Source: Internet
Author: User

Custom NSLog for release and debugging, custom nslog debugging
Problem

  • A large numberNSLogBut you want to cancel theseNSLog
  • Is it often used during development?NSLog(@"%s", __FUNCTION__);
Solve the problem
  • NewExtendNSLogClass, inherited fromNSObject
  • InExtendNSLog.hDelete default code
  • Add the following function declaration:
void ExtendNSLog(const char *file, int lineNumber, const char *functionName, NSString *format, ...);
  • InExtendNSLog.mDelete default code
  • Add the following code:
 1 void ExtendNSLog(const char *file, int lineNumber, const char *functionName, NSString *format, ...) { 2  3     va_list ap; 4  5     va_start(ap, format); 6  7     if (![format hasSuffix: @"\n"]) { 8         format = [format stringByAppendingString: @"\n"]; 9     }10 11     NSString *body = [[NSString alloc] initWithFormat:format arguments:ap];12 13     va_end(ap);14 15     NSString *fileName = [[NSString stringWithUTF8String:file] lastPathComponent];16     fprintf(stderr, "(%s) (%s:%d) %s",17             functionName,18             [fileName UTF8String],19             lineNumber,20             [body UTF8String]);21 }
  • NewPrefixHeader.pchFile
  • Enter the following content:
 1 #ifdef __OBJC__ 2  3 #import <UIKit/UIKit.h> 4 #import <Foundation/Foundation.h> 5  6 #import "ExtendNSLog.h" 7  8 #ifdef DEBUG 9 #define NSLog(args...) ExtendNSLog(__FILE__, __LINE__, __PRETTY_FUNCTION__, args);10 #else11 #define NSLog(x...)12 #endif13 14 #endif
  • SelectProject->TARGETS->[ProjectName]->Build Settings
  • Enter in the search boxprefix header
  • InPrefix HeaderInput[ProjectName]/PrefixHeader.pch

As shown in

  • Run the test, such as modifying the running mode.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.