学科:IOS/KB/变量类型转换

待转换类型 目标类型 方法 备注
NSString 整型(int, integerValue) [NSString intValue], [NSString integerValue]
NSNumber NSString [NSNumber stringValue]
NSDate NSDateComponents [NSCalendar dateFromComponents:]
NSDateComponents NSDate [NSCalendar components:fromDate:], ⋯⋯
NSData NSObject<NSCoding> NSKeyedUnarchiver
NSDictionary/NSArray NSData(plist格式) [NSPropertyListSerialization dataWithPropertyList:format:options:error:]
NSData(plist格式) NSDictionary/NSArray [NSPropertyListSerialization propertyListWithData:options:format:error:]
NSObject<NSCoding> NSData NSKeyedArchiver
UIImage NSData UIImagePNGRepresentation(), UIImageJPEGRepresentation() 不转换类型还是用 NSKeyedArchiver
Core Data Transformable Attribute id NSValueTransformer