AWSNSCodingUtilities

Objective-C

@interface AWSNSCodingUtilities: NSObject

#pragma mark - Archive

/// On iOS 11 and greater, uses `+[NSKeyedArchiver
/// archivedDataWithRootObject:requiringSecureCoding:error:]` to archive data, otherwise uses
/// `+[NSKeyedArchiver archivedDataWithRootObject:]`
+ (nullable NSData *)versionSafeArchivedDataWithRootObject:(id)obj
                                     requiringSecureCoding:(BOOL)requireSecureCoding
                                                     error:(NSError *__autoreleasing *)error;

#pragma mark - Unarchive

/// On iOS 11 and greater, uses `+[NSKeyedUnarchiver
/// unarchivedObjectOfClass:fromData:error:]` to unarchive data, otherwise uses
/// `+[NSKeyedUnarchiver unarchiveObjectWithData:]`
+ (nullable id)versionSafeUnarchivedObjectOfClass:(Class)cls
                                         fromData:(NSData *)data
                                            error:(NSError *__autoreleasing *)error;

/// On iOS 11 and greater, uses `+[NSKeyedUnarchiver
/// unarchivedObjectOfClasses:fromData:error:]` to unarchive data, otherwise uses
/// `+[NSKeyedUnarchiver unarchiveObjectWithData:]`
+ (nullable id)versionSafeUnarchivedObjectOfClasses:(NSSet<Class> *)classes
                                           fromData:(NSData *)data
                                              error:(NSError *__autoreleasing *)error;

/// On iOS 11 and greater, uses `+[NSKeyedUnarchiver
/// unarchivedObjectOfClasses:fromData:error:]` to unarchive data into a mutable
/// dictionary that allows NSDictionary and NSMutableString in its allowed class
/// set, otherwise uses `+[NSKeyedUnarchiver unarchiveObjectWithData:]`
+ (nullable NSMutableDictionary *)versionSafeMutableDictionaryFromData:(NSData *)data
                                                                 error:(NSError *__autoreleasing *)error;

@end

Swift

class AWSNSCodingUtilities : NSObject

Undocumented

Archive

  • On iOS 11 and greater, uses +[NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error:] to archive data, otherwise uses +[NSKeyedArchiver archivedDataWithRootObject:]

    Declaration

    Objective-C

    + (nullable NSData *)
        versionSafeArchivedDataWithRootObject:(nonnull id)obj
                        requiringSecureCoding:(BOOL)requireSecureCoding
                                        error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func versionSafeArchivedData(withRootObject obj: Any, requiringSecureCoding requireSecureCoding: Bool) throws -> Data

Unarchive

  • On iOS 11 and greater, uses +[NSKeyedUnarchiver unarchivedObjectOfClass:fromData:error:] to unarchive data, otherwise uses +[NSKeyedUnarchiver unarchiveObjectWithData:]

    Declaration

    Objective-C

    + (nullable id)
        versionSafeUnarchivedObjectOfClass:(nonnull Class)cls
                                  fromData:(nonnull NSData *)data
                                     error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func versionSafeUnarchivedObject(of cls: AnyClass, from data: Data) throws -> Any
  • On iOS 11 and greater, uses +[NSKeyedUnarchiver unarchivedObjectOfClasses:fromData:error:] to unarchive data, otherwise uses +[NSKeyedUnarchiver unarchiveObjectWithData:]

    Declaration

    Objective-C

    + (nullable id)
        versionSafeUnarchivedObjectOfClasses:(nonnull NSSet<Class> *)classes
                                    fromData:(nonnull NSData *)data
                                       error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func versionSafeUnarchivedObject(ofClasses classes: Set<AnyHashable>, from data: Data) throws -> Any
  • On iOS 11 and greater, uses +[NSKeyedUnarchiver unarchivedObjectOfClasses:fromData:error:] to unarchive data into a mutable dictionary that allows NSDictionary and NSMutableString in its allowed class set, otherwise uses +[NSKeyedUnarchiver unarchiveObjectWithData:]

    Declaration

    Objective-C

    + (nullable NSMutableDictionary *)
        versionSafeMutableDictionaryFromData:(nonnull NSData *)data
                                       error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func versionSafeMutableDictionary(from data: Data) throws -> NSMutableDictionary