类型 | 定义 | 建议 |
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 see below warning when scanning |
CFIndex | %ld or %lx | The same as NSInteger |
pointer | %p | %p adds 0x to the beginning of the output. If you don’t want that, use %lx and cast to long. |
long long | %lld or %llx | long long is 64-bit on both 32- and 64-bit platforms |
unsigned long long | %llu or %llx | unsigned long long is 64-bit on both 32- and 64-bit platforms |
UIKit下,UIGeometry.h中申明了一些相关方法,可以对于一些Struct类型和NSString进行相互转换:
NSString *NSStringFromCGPoint(CGPoint point);
NSString *NSStringFromCGSize(CGSize size);
NSString *NSStringFromCGRect(CGRect rect);
NSString *NSStringFromCGAffineTransform(CGAffineTransform transform);
NSString *NSStringFromUIEdgeInsets(UIEdgeInsets insets);
NSString *NSStringFromUIOffset(UIOffset offset);
CGPoint CGPointFromString(NSString *string);
CGSize CGSizeFromString(NSString *string);
CGRect CGRectFromString(NSString *string);
CGAffineTransform CGAffineTransformFromString(NSString *string);
UIEdgeInsets UIEdgeInsetsFromString(NSString *string);
UIOffset UIOffsetFromString(NSString *string);