• iOS中NSLog输出格式大全


    iOS中NSLog输出格式大全

      1 //
      2 //  ViewController.m
      3 //  NSLog日志输出格式大全
      4 //
      5 //  
      6 //  
      7 //
      8 
      9 #import "ViewController.h"
     10 
     11 @interface ViewController ()
     12 
     13 @end
     14 
     15 @implementation ViewController
     16 
     17 - (void)viewDidLoad {
     18     [super viewDidLoad];
     19     
     20 /*
     21      %@           OC对象
     22      
     23      %d,%i        整型 (%i的老写法)
     24      
     25      %hd          短整型
     26      
     27      %ld,%lld     长整型
     28      
     29      %u           无符整型
     30      
     31      %f           浮点型和double型
     32      
     33      %0.2f        精度浮点数,只保留两位小数
     34      
     35      %x:       为32位的无符号整型数(unsigned int),打印使用数字0-9的十六进制,小写a-f;
     36      
     37      %X:       为32位的无符号整型数(unsigned int),打印使用数字0-9的十六进制,大写A-F;
     38      
     39      %o            八进制
     40      
     41      %zu/%zd       size_t/NSInteger
     42      
     43      %p            指针地址
     44      
     45      %e            float/double(科学计数)
     46      
     47      %g            float/double(科学计数)
     48      
     49      %s            char *  字符串
     50      
     51      %.*s          Pascal字符串
     52      
     53      %c            char 字符
     54      
     55      %C            unichar
     56      
     57      %Lf           64位double
     58      
     59      %lu           sizeof(i)内存中所占字节数
     60     
     61      NSStringFromCGAffineTransform()
     62      NSStringFromCGPoint()
     63      NSStringFromCGRect()
     64      NSStringFromCGSize()
     65      NSStringFromCGVector()
     66      NSStringFromClass()
     67      NSStringFromProtocol()
     68      NSStringFromRange()
     69      NSStringFromSelector() //sel_getName()也可以
     70      NSStringFromUIEdgeInsets()
     71      NSStringFromUIOffset()
     72      
     73 */
     74     
     75     
     76    
     77     /** 几种不同的打印函数 **
     78     NSLog(<#NSString * _Nonnull format, ...#>)     --> OC
     79     printf(<#const char *restrict, ...#>)          --> C
     80     CFShow(<#CFTypeRef obj#>)                      --> Core Foundation
     81     CFShowStr(<#CFStringRef str#>)                 --> Core Foundation
     82      */
     83     
     84     NSLog(@"当前方法名:%@",NSStringFromSelector(_cmd));
     85     NSLog(@"当前方法名: %s",sel_getName(_cmd));
     86     NSLog(@"[类 方法]:%s",__func__);
     87     NSLog(@"[类 方法]:%s",__FUNCTION__);
     88     NSLog(@"当前类名:%@",NSStringFromClass([self class]));
     89     NSLog(@"当前行号:%d",__LINE__);
     90     
     91     NSLog(@"当前文件存储路径:%s",__FILE__);
     92     NSString *pathStr = [NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding]; //将CString -> NSString
     93     NSLog(@"当前文件名:%@",[pathStr lastPathComponent]);
     94     ;
     95     
     96     
     97     NSLog(@"当前日期:%s",__DATE__);
     98     NSLog(@"当前时间:%s",__TIME__);
     99     NSLog(@"当前App运行要求的最低ios版本:%d",__IPHONE_OS_VERSION_MIN_REQUIRED);  //Develop Target: 已选8.0
    100     NSLog(@"当前App支持的最高ios版本:%d",__IPHONE_OS_VERSION_MAX_ALLOWED);    //Develop Target: 最高9.0
    101     NSLog(@"打印__IPHONE_7_0:%d",__IPHONE_7_0);  //打印ios7.0
    102     
    103     NSLog(@"当前线程:%@",[NSThread currentThread]);
    104     NSLog(@"主线程:%@",[NSThread mainThread]);
    105     NSLog(@"当前栈信息:%@", [NSThread callStackSymbols]);
    106  
    107     
    108     
    109     //SEL对象即一个@selector对象,保存一个方法的地址
    110     SEL sel0 = _cmd; //代表当前方法
    111     SEL sel1 = @selector(sayHello);//将sayHello方法包装成SEL对象
    112     SEL sel2 = NSSelectorFromString(@"sayHello"); //从方法名字符串创建SEL对象
    113     [self sayHello];
    114     [self performSelector:sel1];
    115     [self performSelector:sel2 withObject:@"123"];
    116     
    117 }
    118 
    119 - (void)sayHello {
    120 
    121     NSLog(@"Hello, world!");
    122 
    123 }
    124 
    125 @end

    打印结果:

     1 2016-05-14 17:42:47.179 NSLog日志输出格式大全[21214:1404941] 当前方法名:viewDidLoad
     2 2016-05-14 17:42:47.183 NSLog日志输出格式大全[21214:1404941] 当前方法名: viewDidLoad
     3 2016-05-14 17:42:47.183 NSLog日志输出格式大全[21214:1404941] [类 方法]:-[ViewController viewDidLoad]
     4 2016-05-14 17:42:47.183 NSLog日志输出格式大全[21214:1404941] [类 方法]:-[ViewController viewDidLoad]
     5 2016-05-14 17:42:47.183 NSLog日志输出格式大全[21214:1404941] 当前类名:ViewController
     6 2016-05-14 17:42:47.183 NSLog日志输出格式大全[21214:1404941] 当前行号:89
     7 2016-05-14 17:42:47.183 NSLog日志输出格式大全[21214:1404941] 当前文件存储路径:/Users/mac/Desktop/NSLogÊó•ÂøóËæìÂá∫ʆºÂºè§ßÂÖ®/NSLogÊó•ÂøóËæìÂá∫ʆºÂºè§ßÂÖ®/ViewController.m
     8 2016-05-14 17:42:47.184 NSLog日志输出格式大全[21214:1404941] 当前文件名:ViewController.m
     9 2016-05-14 17:42:47.184 NSLog日志输出格式大全[21214:1404941] 当前日期:May 14 2016
    10 2016-05-14 17:42:47.184 NSLog日志输出格式大全[21214:1404941] 当前时间:17:42:44
    11 2016-05-14 17:42:47.225 NSLog日志输出格式大全[21214:1404941] 当前App运行要求的最低ios版本:80000
    12 2016-05-14 17:42:47.225 NSLog日志输出格式大全[21214:1404941] 当前App支持的最高ios版本:90000
    13 2016-05-14 17:42:47.225 NSLog日志输出格式大全[21214:1404941] 打印__IPHONE_7_0:70000
    14 2016-05-14 17:42:47.225 NSLog日志输出格式大全[21214:1404941] 当前线程:<NSThread: 0x7ff779f074b0>{number = 1, name = main}
    15 2016-05-14 17:42:47.225 NSLog日志输出格式大全[21214:1404941] 主线程:<NSThread: 0x7ff779f074b0>{number = 1, name = main}
    16 2016-05-14 17:42:47.228 NSLog日志输出格式大全[21214:1404941] 当前栈信息:(
    17     0   NSLog日志输出格式大全       0x000000010888187e -[ViewController viewDidLoad] + 718
    18     1   UIKit                               0x000000010983f931 -[UIViewController loadViewIfRequired] + 1344
    19     2   UIKit                               0x000000010983fc7d -[UIViewController view] + 27
    20     3   UIKit                               0x000000010971d0c0 -[UIWindow addRootViewControllerViewIfPossible] + 61
    21     4   UIKit                               0x000000010971d7bd -[UIWindow _setHidden:forced:] + 302
    22     5   UIKit                               0x000000010972f020 -[UIWindow makeKeyAndVisible] + 43
    23     6   UIKit                               0x00000001096ac93c -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
    24     7   UIKit                               0x00000001096b2e15 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1755
    25     8   UIKit                               0x00000001096afff0 -[UIApplication workspaceDidEndTransaction:] + 188
    26     9   FrontBoardServices                  0x000000010bfc77ac -[FBSSerialQueue _performNext] + 192
    27     10  FrontBoardServices                  0x000000010bfc7b1a -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    28     11  CoreFoundation                      0x00000001092340a1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    29     12  CoreFoundation                      0x0000000109229fcc __CFRunLoopDoSources0 + 556
    30     13  CoreFoundation                      0x0000000109229483 __CFRunLoopRun + 867
    31     14  CoreFoundation                      0x0000000109228e98 CFRunLoopRunSpecific + 488
    32     15  UIKit                               0x00000001096af98d -[UIApplication _run] + 402
    33     16  UIKit                               0x00000001096b4676 UIApplicationMain + 171
    34     17  NSLog日志输出格式大全       0x0000000108881c7f main + 111
    35     18  libdyld.dylib                       0x000000010b99392d start + 1
    36 )
    37 2016-05-14 17:42:47.285 NSLog日志输出格式大全[21214:1404941] Hello, world!
    38 2016-05-14 17:42:47.285 NSLog日志输出格式大全[21214:1404941] Hello, world!
    39 2016-05-14 17:42:47.285 NSLog日志输出格式大全[21214:1404941] Hello, world!
  • 相关阅读:
    疯狂学java的第32天
    疯狂学java的第31天
    疯狂学java的第30天
    疯狂学java的第29天
    疯狂学java的第28天
    javaSE_day14_抽象类
    javaSE_day13_继承、super、this
    JavaSE_day12_static关键字丶单列设计模式丶代码块
    JavaSE_day11_常用类(String类丶StringBuffer类丶StringBuilder类)
    JavaSE_day10_初识API丶常用类(Scanner丶Random丶ArrayList)
  • 原文地址:https://www.cnblogs.com/stevenwuzheng/p/5485986.html
Copyright © 2020-2023  润新知