EditorContentEncoder

public protocol EditorContentEncoder : EditorContentEncoding

A generic encoder for encoding EditorContent. You may create encoders for individual types of contents in the Editor, and use EditorContentEncoder to register and encode the all the contents of the given EditorView.

Usage Example

typealias JSON = [String: Any]
struct JSONEncoder: EditorContentEncoder {
    let textEncoders: [EditorContent.Name: AnyEditorTextEncoding<JSON>] = [
        .paragraph: AnyEditorTextEncoding(ParagraphEncoder()),
        .text: AnyEditorTextEncoding(TextEncoder())
    ]
    let attachmentEncoders: [EditorContent.Name: AnyEditorContentAttachmentEncoding<JSON>] = [
       .panel: AnyEditorContentAttachmentEncoding(PanelEncoder()),
       .media: AnyEditorContentAttachmentEncoding(MediaEncoder()),
    ]
}

// Get the encoded content from the editor
let encodedContent = editor.transformContents(using: JSONEncoder())
  • T

    Undocumented

    Declaration

    Swift

    associatedtype T
  • Encoders for text content i.e. NSAttributedString based content

    Declaration

    Swift

    var textEncoders: [EditorContent.Name : AnyEditorTextEncoding<T>] { get }
  • Encoders for attachment types

    Declaration

    Swift

    var attachmentEncoders: [EditorContent.Name : AnyEditorContentAttachmentEncoding<T>] { get }
  • encode(_:) Default implementation

    Encodes the given content.

    Note

    A default implementation is already provided which automatically uses correct encoder based on the content to encode. The default implementation should be sufficient for most unless you need to add additional behaviour like logging. analytics etc.

    Default Implementation

    Declaration

    Swift

    func encode(_ content: EditorContent) -> T!

    Parameters

    content

    Content to encode