String Format Specifiers
2018-06-21 本文已影响0人
Dayon
| Type | Format specifier | Considerations |
|---|---|---|
| NSString | %@ | Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function. |
| int | %d, %D | Signed 32-bit integer (int). |
| (unsigned int | %u, %U | Unsigned 32-bit integer (unsigned int). |
| double | %f | 64-bit floating-point number (double). |
| (unsigned int | %u, %U | Unsigned 32-bit integer (unsigned int). |
| NSInteger | %ld or %lx | Cast the value to long. |
| NSUInteger | %lu or %lx | Cast the value to unsigned long. |
| CGFloat | %f or %g | %f works for floats and doubles when formatting; but note the technique described below for scanning. |
| CFIndex | %ld or %lx | The same as NSInteger. |
| pointer | %p or %zx | %p adds 0x to the beginning of the output. If you don't want that, use %zx and no typecast. |