diff --git a/Aztec/Classes/EditorView/EditorView.swift b/Aztec/Classes/EditorView/EditorView.swift index 959f9724f..1328d6b96 100644 --- a/Aztec/Classes/EditorView/EditorView.swift +++ b/Aztec/Classes/EditorView/EditorView.swift @@ -99,8 +99,8 @@ public class EditorView: UIView { // MARK: - Initializers public required init?(coder aDecoder: NSCoder) { - guard let htmlTextView = aDecoder.decodeObject(forKey: EditorView.htmlTextViewKey) as? UITextView, - let richTextView = aDecoder.decodeObject(forKey: EditorView.richTextViewKey) as? TextView else { + guard let htmlTextView = aDecoder.decodeObject(of: UITextView.self, forKey: EditorView.htmlTextViewKey), + let richTextView = aDecoder.decodeObject(of: TextView.self, forKey: EditorView.richTextViewKey) else { return nil } diff --git a/Aztec/Classes/Extensions/NSAttributedString+Archive.swift b/Aztec/Classes/Extensions/NSAttributedString+Archive.swift index cb0014ba9..81997e2e1 100644 --- a/Aztec/Classes/Extensions/NSAttributedString+Archive.swift +++ b/Aztec/Classes/Extensions/NSAttributedString+Archive.swift @@ -11,7 +11,7 @@ extension NSAttributedString } static func unarchive(with data: Data) throws -> NSAttributedString? { - return try NSKeyedUnarchiver.unarchivedObject(ofClass: NSAttributedString.self, from: data) + return try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSAttributedString.self, HTMLRepresentation.self], from: data) as? NSAttributedString } } diff --git a/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift b/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift index 7016a903d..ef50ef97f 100644 --- a/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift +++ b/Aztec/Classes/Libxml2/DOM/Data/Attribute.swift @@ -3,7 +3,7 @@ import Foundation /// Represents a basic attribute with no value. This is also the base class for all other /// attributes. /// -public class Attribute: NSObject, CustomReflectable, NSCoding { +public class Attribute: NSObject, CustomReflectable, NSSecureCoding { // MARK: - Attribute Definition Properties @@ -52,15 +52,15 @@ public class Attribute: NSObject, CustomReflectable, NSCoding { public required convenience init?(coder aDecoder: NSCoder) { // TODO: This is a Work in Progress. Let's also get Attribute conforming to Codable! - guard let name = aDecoder.decodeObject(forKey: Keys.name) as? String, - let rawValue = aDecoder.decodeObject(forKey: Keys.value) as? Data, - let value = try? JSONDecoder().decode(Value.self, from: rawValue) else + guard let name = aDecoder.decodeObject(of: NSString.self, forKey: Keys.name), + let rawValue = aDecoder.decodeObject(of: NSData.self, forKey: Keys.value), + let value = try? JSONDecoder().decode(Value.self, from: rawValue as Data) else { assertionFailure("Review the logic.") return nil } - self.init(name: name, value: value) + self.init(name: name as String, value: value) } open func encode(with aCoder: NSCoder) { @@ -72,6 +72,8 @@ public class Attribute: NSObject, CustomReflectable, NSCoding { } } + public class var supportsSecureCoding: Bool { true } + // MARK: - Equatable public override func isEqual(_ object: Any?) -> Bool { diff --git a/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift b/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift index f14e60331..6c859b88e 100644 --- a/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift +++ b/Aztec/Classes/NSAttributedString/Attributes/HTMLRepresentation.swift @@ -2,7 +2,7 @@ import Foundation /// This enum specifies the different entities that can represent a style in HTML. /// -public class HTMLRepresentation: NSObject, NSCoding { +public class HTMLRepresentation: NSObject, NSSecureCoding { public enum Kind { case attribute(Attribute) case element(HTMLElementRepresentation) @@ -24,18 +24,18 @@ public class HTMLRepresentation: NSObject, NSCoding { } public required init?(coder aDecoder: NSCoder) { - if let attribute = aDecoder.decodeObject(forKey: Keys.attribute) as? Attribute { + if let attribute = aDecoder.decodeObject(of: Attribute.self, forKey: Keys.attribute) { kind = .attribute(attribute) return } - if let element = aDecoder.decodeObject(forKey: Keys.element) as? HTMLElementRepresentation { + if let element = aDecoder.decodeObject(of: HTMLElementRepresentation.self, forKey: Keys.element) { kind = .element(element) return } - if let rawCSS = aDecoder.decodeObject(forKey: Keys.inline) as? String, - let decodedCSS = CSSAttribute(for: rawCSS) { + if let rawCSS = aDecoder.decodeObject(of: NSString.self, forKey: Keys.inline), + let decodedCSS = CSSAttribute(for: rawCSS as String) { kind = .inlineCss(decodedCSS) return } @@ -53,12 +53,14 @@ public class HTMLRepresentation: NSObject, NSCoding { aCoder.encode(css.toString(), forKey: Keys.inline) } } + + public class var supportsSecureCoding: Bool { true } } // MARK: - HTMLElementRepresentation // -public class HTMLElementRepresentation: NSObject, CustomReflectable, NSCoding { +public class HTMLElementRepresentation: NSObject, CustomReflectable, NSSecureCoding { @objc let name: String @objc let attributes: [Attribute] @@ -78,13 +80,21 @@ public class HTMLElementRepresentation: NSObject, CustomReflectable, NSCoding { // MARK: - NSCoding public required convenience init?(coder aDecoder: NSCoder) { - guard let name = aDecoder.decodeObject(forKey: #keyPath(name)) as? String, - let attributes = aDecoder.decodeObject(forKey: #keyPath(attributes)) as? [Attribute] - else { + guard let name = aDecoder.decodeObject(of: NSString.self, forKey: #keyPath(name)) else { + fatalError() + } + let decodedAttributes: [Attribute]? + + if #available(iOS 14.0, *) { + decodedAttributes = aDecoder.decodeArrayOfObjects(ofClass: Attribute.self, forKey: #keyPath(attributes)) + } else { + decodedAttributes = aDecoder.decodeObject(of: NSArray.self, forKey: #keyPath(attributes)) as? [Attribute] + } + guard let attributes = decodedAttributes else { fatalError() } - self.init(name: name, attributes: attributes) + self.init(name: name as String, attributes: attributes) } open func encode(with aCoder: NSCoder) { @@ -92,6 +102,8 @@ public class HTMLElementRepresentation: NSObject, CustomReflectable, NSCoding { aCoder.encode(attributes, forKey: #keyPath(attributes)) } + public class var supportsSecureCoding: Bool { true } + // MARK: - CustomReflectable public var customMirror: Mirror { diff --git a/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift b/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift index 946b0a2e2..ace5b5556 100644 --- a/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift +++ b/Aztec/Classes/NSAttributedString/Attributes/UnsupportedHTML.swift @@ -3,7 +3,7 @@ import Foundation // MARK: - UnsupportedHTML // -class UnsupportedHTML: NSObject { +class UnsupportedHTML: NSObject, NSSecureCoding { /// ElementRepresentation for Unsupported HTML /// @@ -18,12 +18,20 @@ class UnsupportedHTML: NSObject { /// Required Initializers /// public required init?(coder aDecoder: NSCoder) { - guard let representations = aDecoder.decodeObject(forKey: Keys.representations) as? [HTMLElementRepresentation] else { - return nil + let representations: [HTMLElementRepresentation]? + if #available(iOS 14.0, *) { + representations = aDecoder.decodeArrayOfObjects(ofClass: HTMLElementRepresentation.self, forKey: Keys.representations) + } else { + representations = aDecoder.decodeObject(of: NSArray.self, forKey: Keys.representations) as? [HTMLElementRepresentation] } + guard let representations else { + return nil + } self.representations = representations } + + class var supportsSecureCoding: Bool { true } } diff --git a/Aztec/Classes/TextKit/CommentAttachment.swift b/Aztec/Classes/TextKit/CommentAttachment.swift index dd726b1b5..a2aeb3093 100644 --- a/Aztec/Classes/TextKit/CommentAttachment.swift +++ b/Aztec/Classes/TextKit/CommentAttachment.swift @@ -32,11 +32,11 @@ open class CommentAttachment: NSTextAttachment, RenderableAttachment { public required init?(coder aDecoder: NSCoder) { super.init(data: nil, ofType: nil) - guard let text = aDecoder.decodeObject(forKey: Keys.text) as? String else { + guard let text = aDecoder.decodeObject(of: NSString.self, forKey: Keys.text) else { return } - self.text = text + self.text = text as String } @@ -48,7 +48,7 @@ open class CommentAttachment: NSTextAttachment, RenderableAttachment { aCoder.encode(text, forKey: Keys.text) } - + override public class var supportsSecureCoding: Bool { true } // MARK: - NSTextAttachmentContainer diff --git a/Aztec/Classes/TextKit/HTMLAttachment.swift b/Aztec/Classes/TextKit/HTMLAttachment.swift index 971f0bb8a..464601f25 100644 --- a/Aztec/Classes/TextKit/HTMLAttachment.swift +++ b/Aztec/Classes/TextKit/HTMLAttachment.swift @@ -40,16 +40,17 @@ open class HTMLAttachment: NSTextAttachment, RenderableAttachment { public required init?(coder aDecoder: NSCoder) { super.init(data: nil, ofType: nil) - guard let rootTagName = aDecoder.decodeObject(forKey: Keys.rootTagName) as? String, - let rawHTML = aDecoder.decodeObject(forKey: Keys.rawHTML) as? String + guard let rootTagName = aDecoder.decodeObject(of: NSString.self, forKey: Keys.rootTagName), + let rawHTML = aDecoder.decodeObject(of: NSString.self, forKey: Keys.rawHTML) else { return } - self.rootTagName = rootTagName - self.rawHTML = rawHTML + self.rootTagName = rootTagName as String + self.rawHTML = rawHTML as String } + override public class var supportsSecureCoding: Bool { true } /// Extracts the root tag name from a given HTML string /// diff --git a/Aztec/Classes/TextKit/ImageAttachment.swift b/Aztec/Classes/TextKit/ImageAttachment.swift index 60007086f..f60f170f0 100644 --- a/Aztec/Classes/TextKit/ImageAttachment.swift +++ b/Aztec/Classes/TextKit/ImageAttachment.swift @@ -74,6 +74,8 @@ open class ImageAttachment: MediaAttachment { aCoder.encode(size.rawValue, forKey: EncodeKeys.size.rawValue) } + override public class var supportsSecureCoding: Bool { true } + private enum EncodeKeys: String { case alignment case size diff --git a/Aztec/Classes/TextKit/MediaAttachment.swift b/Aztec/Classes/TextKit/MediaAttachment.swift index b2265d5df..53faa52ab 100644 --- a/Aztec/Classes/TextKit/MediaAttachment.swift +++ b/Aztec/Classes/TextKit/MediaAttachment.swift @@ -153,10 +153,12 @@ open class MediaAttachment: NSTextAttachment { /// super.init(coder: aDecoder) - identifier = aDecoder.decodeObject(forKey: EncodeKeys.identifier.rawValue) as? String ?? identifier - url = aDecoder.decodeObject(forKey: EncodeKeys.url.rawValue) as? URL + identifier = aDecoder.decodeObject(of: NSString.self, forKey: EncodeKeys.identifier.rawValue) as? String ?? identifier + url = aDecoder.decodeObject(of: NSURL.self, forKey: EncodeKeys.url.rawValue) as? URL } + override public class var supportsSecureCoding: Bool { true } + /// Required Initializer /// override required public init(data contentData: Data?, ofType uti: String?) { diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift b/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift index 4e8de163f..477b533a2 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Blockquote.swift @@ -6,6 +6,8 @@ class Blockquote: ParagraphProperty { super.encode(with: aCoder) } + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift b/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift index 388d6fb11..9c23bed4e 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Figcaption.swift @@ -10,7 +10,7 @@ class Figcaption: ParagraphProperty { } required public init?(coder aDecoder: NSCoder){ - defaultFont = aDecoder.decodeObject(forKey: CodingKeys.defaultFont) as! UIFont + defaultFont = aDecoder.decodeObject(of: UIFont.self, forKey: CodingKeys.defaultFont)! super.init(coder: aDecoder) } @@ -18,6 +18,8 @@ class Figcaption: ParagraphProperty { super.encode(with: aCoder) aCoder.encode(defaultFont, forKey: CodingKeys.defaultFont) } + + override public class var supportsSecureCoding: Bool { true } } private extension Figcaption { diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift b/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift index ef2c75dc9..beffb410e 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Figure.swift @@ -5,7 +5,9 @@ class Figure: ParagraphProperty { public override func encode(with aCoder: NSCoder) { super.encode(with: aCoder) } - + + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift index 7dd45a23a..15947898d 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLDiv.swift @@ -9,6 +9,8 @@ class HTMLDiv: ParagraphProperty { super.encode(with: aCoder) } + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift index 2b0310058..0485360b3 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLLi.swift @@ -6,6 +6,8 @@ class HTMLLi: ParagraphProperty { super.encode(with: aCoder) } + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift index 83aa956a9..9432886f7 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLParagraph.swift @@ -9,6 +9,8 @@ class HTMLParagraph: ParagraphProperty { super.encode(with: aCoder) } + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift b/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift index d8049c139..ca043a51c 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/HTMLPre.swift @@ -6,6 +6,8 @@ class HTMLPre: ParagraphProperty { super.encode(with: aCoder) } + override public class var supportsSecureCoding: Bool { true } + override public init(with representation: HTMLRepresentation? = nil) { super.init(with: representation) } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Header.swift b/Aztec/Classes/TextKit/ParagraphProperty/Header.swift index a13dafe0c..d5120720a 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Header.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Header.swift @@ -83,6 +83,8 @@ open class Header: ParagraphProperty { aCoder.encode(level.rawValue, forKey: Keys.level) } + override public class var supportsSecureCoding: Bool { true } + static func ==(lhs: Header, rhs: Header) -> Bool { return lhs.level == rhs.level } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift b/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift index 0a6e54180..79ad14b59 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/ParagraphProperty.swift @@ -1,6 +1,6 @@ import Foundation -open class ParagraphProperty: NSObject, NSCoding { +open class ParagraphProperty: NSObject, NSSecureCoding { open var representation: HTMLRepresentation? @@ -19,6 +19,8 @@ open class ParagraphProperty: NSObject, NSCoding { public func encode(with aCoder: NSCoder) { } + public class var supportsSecureCoding: Bool { true } + static func ==(lhs: ParagraphProperty, rhs: ParagraphProperty) -> Bool { return lhs === rhs } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift b/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift index a2cf28306..904118e4e 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift @@ -84,6 +84,8 @@ open class TextList: ParagraphProperty { aCoder.encode(reversed, forKey: AttributeType.reversed.rawValue) } + override public class var supportsSecureCoding: Bool { true } + public static func ==(lhs: TextList, rhs: TextList) -> Bool { return lhs.style == rhs.style && lhs.start == rhs.start && lhs.reversed == rhs.reversed } diff --git a/Aztec/Classes/TextKit/ParagraphStyle.swift b/Aztec/Classes/TextKit/ParagraphStyle.swift index eb01f7029..87d72ece9 100644 --- a/Aztec/Classes/TextKit/ParagraphStyle.swift +++ b/Aztec/Classes/TextKit/ParagraphStyle.swift @@ -89,7 +89,14 @@ open class ParagraphStyle: NSMutableParagraphStyle, CustomReflectable { public required init?(coder aDecoder: NSCoder) { - if let encodedProperties = aDecoder.decodeObject(forKey:String(describing: ParagraphProperty.self)) as? [ParagraphProperty] { + let encodedProperties: [ParagraphProperty]? + if #available(iOS 14.0, *) { + encodedProperties = aDecoder.decodeArrayOfObjects(ofClass: ParagraphProperty.self, forKey: String(describing: ParagraphProperty.self)) + } else { + encodedProperties = aDecoder.decodeObject(of: NSArray.self, forKey: String(describing: ParagraphProperty.self)) as? [ParagraphProperty] + } + + if let encodedProperties { properties = encodedProperties } @@ -105,6 +112,8 @@ open class ParagraphStyle: NSMutableParagraphStyle, CustomReflectable { aCoder.encode(headerLevel, forKey: EncodingKeys.headerLevel.rawValue) } + override public class var supportsSecureCoding: Bool { true } + override open func setParagraphStyle(_ baseParagraphStyle: NSParagraphStyle) { super.setParagraphStyle(baseParagraphStyle) diff --git a/Aztec/Classes/TextKit/VideoAttachment.swift b/Aztec/Classes/TextKit/VideoAttachment.swift index 35df36209..89e82c994 100644 --- a/Aztec/Classes/TextKit/VideoAttachment.swift +++ b/Aztec/Classes/TextKit/VideoAttachment.swift @@ -39,10 +39,12 @@ open class VideoAttachment: MediaAttachment { super.init(coder: aDecoder) if aDecoder.containsValue(forKey: EncodeKeys.posterURL.rawValue) { - posterURL = aDecoder.decodeObject(forKey: EncodeKeys.posterURL.rawValue) as? URL + posterURL = aDecoder.decodeObject(of: NSURL.self, forKey: EncodeKeys.posterURL.rawValue) as? URL } } + override public class var supportsSecureCoding: Bool { true } + /// Required Initializer /// required public init(identifier: String, url: URL?) { diff --git a/AztecTests/TextKit/HTMLRepresentationTests.swift b/AztecTests/TextKit/HTMLRepresentationTests.swift index 47c46b762..6a6998efc 100644 --- a/AztecTests/TextKit/HTMLRepresentationTests.swift +++ b/AztecTests/TextKit/HTMLRepresentationTests.swift @@ -8,9 +8,9 @@ class HTMLRepresentationTests: XCTestCase { /// Verifies that HTMLRepresentation of Attribute kind is properly serialized Back and Forth /// - func testAttibuteRepresentationGetsProperlySerializedAndRestored() { + func testAttibuteRepresentationGetsProperlySerializedAndRestored() throws { let representation = HTMLRepresentation(for: .attribute(sampleAttribute)) - let regenerated = regenerate(representation: representation) + let regenerated = try regenerate(representation: representation) guard case let .attribute(attribute) = regenerated.kind else { XCTFail() @@ -22,9 +22,9 @@ class HTMLRepresentationTests: XCTestCase { /// Verifies that HTMLRepresentation of Element kind is properly serialized Back and Forth /// - func testElementRepresentationGetsProperlySerializedAndRestored() { + func testElementRepresentationGetsProperlySerializedAndRestored() throws { let representation = HTMLRepresentation(for: .element(sampleElement)) - let regenerated = regenerate(representation: representation) + let regenerated = try regenerate(representation: representation) guard case let .element(element) = regenerated.kind else { XCTFail() @@ -36,9 +36,9 @@ class HTMLRepresentationTests: XCTestCase { /// Verifies that HTMLRepresentation of inlineCSS kind is properly serialized Back and Forth /// - func testCssRepresentationGetsProperlySerializedAndRestored() { + func testCssRepresentationGetsProperlySerializedAndRestored() throws { let representation = HTMLRepresentation(for: .inlineCss(sampleCSS)) - let regenerated = regenerate(representation: representation) + let regenerated = try regenerate(representation: representation) guard case let .inlineCss(css) = regenerated.kind else { XCTFail() @@ -67,12 +67,10 @@ private extension HTMLRepresentationTests { return HTMLElementRepresentation(name: "table", attributes: [sampleAttribute]) } - func regenerate(representation: HTMLRepresentation) -> HTMLRepresentation { - let data = NSKeyedArchiver.archivedData(withRootObject: representation) - guard let restored = NSKeyedUnarchiver.unarchiveObject(with: data) as? HTMLRepresentation else { - fatalError() - } + func regenerate(representation: HTMLRepresentation) throws -> HTMLRepresentation { + let data = try NSKeyedArchiver.archivedData(withRootObject: representation, requiringSecureCoding: false) + let restored = try NSKeyedUnarchiver.unarchivedObject(ofClass: HTMLRepresentation.self, from: data) - return restored + return restored! } } diff --git a/AztecTests/TextKit/UnsupportedHTMLTests.swift b/AztecTests/TextKit/UnsupportedHTMLTests.swift index 11b100ad6..2588953a5 100644 --- a/AztecTests/TextKit/UnsupportedHTMLTests.swift +++ b/AztecTests/TextKit/UnsupportedHTMLTests.swift @@ -8,11 +8,11 @@ class UnsupportedHTMLTests: XCTestCase { /// Verifies that a UnsupportedHTML Instance can get properly serialized back and forth /// - func testSnippetsGetProperlyEncodedAndDecoded() { + func testSnippetsGetProperlyEncodedAndDecoded() throws { let unsupported = UnsupportedHTML(representations: [sampleRepresentation, sampleRepresentation]) - let data = NSKeyedArchiver.archivedData(withRootObject: unsupported) - guard let restored = NSKeyedUnarchiver.unarchiveObject(with: data) as? UnsupportedHTML else { + let data = try NSKeyedArchiver.archivedData(withRootObject: unsupported, requiringSecureCoding: false) + guard let restored = try NSKeyedUnarchiver.unarchivedObject(ofClass: UnsupportedHTML.self, from: data) else { XCTFail() return } diff --git a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift index 6ead4ee47..655d2887c 100644 --- a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift +++ b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/Gutenblock.swift @@ -10,4 +10,7 @@ class Gutenblock: ParagraphProperty { required public init?(coder aDecoder: NSCoder){ super.init(coder: aDecoder) } + + override public class var supportsSecureCoding: Bool { true } + } diff --git a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/GutenpackAttachment.swift b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/GutenpackAttachment.swift index 784343f0d..f45d42e4f 100644 --- a/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/GutenpackAttachment.swift +++ b/WordPressEditor/WordPressEditor/Classes/Plugins/WordPressPlugin/Gutenberg/GutenpackAttachment.swift @@ -17,14 +17,14 @@ class GutenpackAttachment: NSTextAttachment, RenderableAttachment { let blockContent: String required init?(coder aDecoder: NSCoder) { - guard let blockName = aDecoder.decodeObject(forKey: EncodingKeys.blockName) as? String, - let blockContent = aDecoder.decodeObject(forKey: EncodingKeys.blockContent) as? String + guard let blockName = aDecoder.decodeObject(of: NSString.self, forKey: EncodingKeys.blockName), + let blockContent = aDecoder.decodeObject(of: NSString.self, forKey: EncodingKeys.blockContent) else { return nil } - self.blockName = blockName - self.blockContent = blockContent + self.blockName = blockName as String + self.blockContent = blockContent as String super.init(coder: aDecoder) }