diff --git a/Parse/Parse/Source/PFFileObject.h b/Parse/Parse/Source/PFFileObject.h index acb275150..c01110f95 100644 --- a/Parse/Parse/Source/PFFileObject.h +++ b/Parse/Parse/Source/PFFileObject.h @@ -31,7 +31,14 @@ __attribute__((unavailable("PFFile was renamed to PFFileObject. Please use it in `PFFileObject` representes a file of binary data stored on the Parse servers. This can be a image, video, or anything else that an application needs to reference in a non-relational way. */ -@interface PFFileObject : NSObject +@interface PFFileObject : NSObject + +/** + Class property required for NSSecureCoding: also it must return YES + + @return Whether the class supports NSSecureCoding.. + */ ++ (BOOL)supportsSecureCoding; ///-------------------------------------- #pragma mark - Creating a PFFileObject diff --git a/Parse/Parse/Source/PFFileObject.m b/Parse/Parse/Source/PFFileObject.m index 4eb2af56e..c322ff99a 100644 --- a/Parse/Parse/Source/PFFileObject.m +++ b/Parse/Parse/Source/PFFileObject.m @@ -51,6 +51,8 @@ @implementation PFFileObject @synthesize stagedFilePath = _stagedFilePath; ++ (BOOL)supportsSecureCoding { return YES; } + ///-------------------------------------- #pragma mark - Public ///-------------------------------------- @@ -503,6 +505,24 @@ + (PFFileController *)fileController { return [Parse _currentManager].coreManager.fileController; } +#pragma mark - NSSecureCoding + +- (void)encodeWithCoder:(NSCoder *)coder { + PFEncoder *encoder = [PFEncoder objectEncoder]; + __autoreleasing NSError *error; + NSDictionary *dict = [encoder encodeObject:self error:&error]; + if (dict && error == nil) { + [coder encodeObject:dict]; + } +} + +- (nullable instancetype)initWithCoder:(NSCoder *)coder { + NSDictionary *dict = [coder decodeObject]; + PFDecoder *decoder = [PFDecoder objectDecoder]; + PFFileObject *fileObject = [decoder decodeObject:dict]; + return (fileObject.name && fileObject.url) ? fileObject : nil; +} + @end ///--------------------------------------