學科: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