Skip to content

Commit

Permalink
-修复序列化缺少文字贴图的数据
Browse files Browse the repository at this point in the history
  • Loading branch information
lincf0912 committed Nov 13, 2020
1 parent d0961e9 commit f937e93
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ - (instancetype)initWithCoder:(NSCoder *)coder
if (self) {
_main = [coder decodeBoolForKey:@"main"];
_image = [coder decodeObjectForKey:@"image"];
_text = [coder decodeObjectForKey:@"text"];
NSURL *assetURL = [coder decodeObjectForKey:@"assetURL"];
if (assetURL) {
_asset = [AVAsset assetWithURL:assetURL];
Expand All @@ -178,6 +179,7 @@ - (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeBool:self.isMain forKey:@"main"];
[coder encodeObject:self.image forKey:@"image"];
[coder encodeObject:self.text forKey:@"text"];
if ([_asset isKindOfClass:[AVURLAsset class]]) {
NSURL *assetURL = ((AVURLAsset *)_asset).URL;
[coder encodeObject:assetURL forKey:@"assetURL"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <UIKit/UIKit.h>

@interface LFText : NSObject
@interface LFText : NSObject <NSSecureCoding>

//@property (nonatomic, copy) NSString *text;
//@property (nonatomic, strong) UIFont *font;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,28 @@ - (instancetype)init
return self;
}

#pragma mark - NSSecureCoding
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super init];
if (self) {
_attributedText = [coder decodeObjectForKey:@"attributedText"];
_layoutData = [coder decodeObjectForKey:@"layoutData"];
_usedRect = [coder decodeCGRectForKey:@"usedRect"];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:self.attributedText forKey:@"attributedText"];
[coder encodeObject:self.layoutData forKey:@"layoutData"];
[coder encodeCGRect:self.usedRect forKey:@"usedRect"];
}

+ (BOOL)supportsSecureCoding
{
return YES;
}

@end

0 comments on commit f937e93

Please sign in to comment.