NSLog中的%@

NSLog中的%@

  There is one additional substitution token available in Objective-C, %@, used to denote an object. At runtime, this specifier will be substituted with the result of calling either the descriptionWithLocale: method (if it exists) or the description method on the provided object. The description method is implemented by NSObject to return the class and memory address of the object, but many Cocoa and Cocoa Touch classes override it to provide more useful information. In the case of NSString, the description method simply returns the string of characters that it represents.

  NSLog与printf相比,添加了%@这么一个输出格式,%@对应的对象在编译后会被替换为对descriptionWithLocal方法的调用,如果此方法不存在,则替换为description方法的调用 。

原文地址:https://www.cnblogs.com/tekkaman/p/3550862.html