是否有关于NSLog()内可以使用的所有代码的概述? [英] Is there an overview of all codes that can be used inside NSLog()?
问题描述
即%@表示字符串,%f表示双打...我不知道这些占位符的含义,但是如果能找到如何打印布尔值和其他值的列表,那就太好了.
i.e. %@ for strings, %f for doubles... I don't know the word for these placeholders but it would be great to have list for how to print booleans and other values.
推荐答案
由于 NSLog
将 NSString
作为其参数,因此它使用 NSString
格式说明符.这实际上与常见的 printf
说明符相同.另外,%@
指示符不限于 NSString
对象,而是用于任何Objective-C对象.基本的 NSObject
类提供了由对象的类及其地址组成的对象的一般描述,但是许多对象会提供特定于其类型的信息,例如集合类( NSArray
, NSDictionary
),它将提供格式正确的内容转储.您可以通过覆盖 -description
为创建的自己的对象提供此功能(有关更多信息,包括本地化功能,请参阅文档).
Since NSLog
takes a NSString
as its argument, it uses the NSString
format specifiers. This is virtually identical to the common printf
specifiers. Also, the %@
specifier is not limited to NSString
objects, but is for any Objective-C objects. The base NSObject
class provides a generic description of the object consisting of its class and its address, but many objects will supply information specific to their type, such as the collection classes (NSArray
, NSDictionary
) which will supply nicely formated dump of their contents. You can provide this for your own objects that you create by overriding -description
(see the documentation for more info, including localization capability).
另请参见: NSString格式说明符
这篇关于是否有关于NSLog()内可以使用的所有代码的概述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!