forked from eladb/Parse-NSCoding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PFFileObject+NSCoding.m
43 lines (36 loc) · 1.01 KB
/
PFFileObject+NSCoding.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// PFFile+NSCoding.m
// UpdateZen
//
// Created by Martin Rybak on 2/3/14.
// Copyright (c) 2014 UpdateZen. All rights reserved.
//
#import "PFFileObject+NSCoding.h"
#import <objc/runtime.h>
#define kPFFileName @"_name"
#define kPFFileURL @"_url"
#define kPFFileData @"data"
@implementation PFFileObject (NSCoding)
- (void)encodeWithCoder:(NSCoder*)encoder
{
[encoder encodeObject:self.name forKey:kPFFileName];
[encoder encodeObject:self.url forKey:kPFFileURL];
if (self.isDataAvailable) {
[encoder encodeObject:[self getData] forKey:kPFFileData];
}
}
- (id)initWithCoder:(NSCoder*)aDecoder
{
NSString* name = [aDecoder decodeObjectForKey:kPFFileName];
NSString* url = [aDecoder decodeObjectForKey:kPFFileURL];
NSData* data = [aDecoder decodeObjectForKey:kPFFileData];
if (data) {
self = [PFFileObject fileObjectWithName:name data:data];
if (self) {
[self setValue:url forKey:@"_url"];
}
return self;
}
return nil;
}
@end