Protocols

The following protocols are available globally.

  • An object capable of resolving text asynchronously to another representation. New representation may contain change in attributes or the string itself.

    See more

    Declaration

    Swift

    public protocol AsyncTextResolving
  • Describes an object (typically attachment view) that may change size during the layout pass

    See more

    Declaration

    Swift

    public protocol DynamicBoundsProviding : AnyObject
  • Denotes an Attachmentcontent view that observes background color changes in containerEditorView

    See more

    Declaration

    Swift

    public protocol BackgroundColorObserving : UIView
  • Describes an object capable of providing offsets for the Attachment. The value is used to offset the Attachment when rendered alongside the text. This may be used to align the content baselines in Attachment content to that of it’s container’s content baselines.

    Note

    This function may be called m0re than once in the same rendering pass. Changing offsets does not resize the container i.e. unlike how container resizes to fit the attachment, if the offset is change such that the attachment ends up rendering outside the bounds of it’s container, it will not resize the container.

    Attention

    While offset can be provided for any type of Attachment i.e. Inline or Block, it is recommended that offset be provided only for Inline. If an offset is provided for Block attachment, it is possible that the attachment starts overlapping the content in Editor in the following line since the offset does not affect the line height.
    See more

    Declaration

    Swift

    public protocol AttachmentOffsetProviding : AnyObject
  • Describes an object that fulfils requirements to enable asynchronous rendering of attachments in the EditorView

    See more

    Declaration

    Swift

    public protocol AsyncAttachmentRenderingDelegate : AnyObject
  • Marker protocol for attachment views that may need to defer completion of rendering in asynchronous mode until the view bounds are changed. This may be important for cases like GridView that does not directly contain the Editors within but instead hosts another view that in turn hosts multiple editors i.e. one per cell. Conformance to this protocol defers invoking the didRenderAttachment on AsyncAttachmentRenderingDelegate until the view size are changed to a non-zero value. In absence of this, didRenderAttachment is invoked as soon as the attachment is rendered in the editor.

    Important

    In almost all the cases where the EditorView is hosted directly inside the attachment, this conformance is not required and not advised. When used in such cases, the async rendering may result in unexpected results. This is advisable only in case the didRenderAttachment is getting triggered sooner than the layout of view within the Attachment is able to complete.

    Declaration

    Swift

    public protocol AsyncDeferredRenderable
  • Describes an object capable of gaining focus.

    Note

    If a content view in an Attachment is made Focusable, setFocus will automatically be called when the attachment with a focusable view is added to the editor.
    See more

    Declaration

    Swift

    public protocol Focusable
  • Describes an object capable of providing numbers to be displayed when isLineNumbersEnabled is set to true in EditorView

    See more

    Declaration

    Swift

    public protocol LineNumberProvider : AnyObject
  • Describes an object capable of providing style and formatting information for rendering lists in EditorView.

    See more

    Declaration

    Swift

    public protocol EditorListFormattingProvider : AnyObject
  • Represents a Sequence generator that can return a value based on given index. Besides other possible uses, this is used in Lists for generation of bullets/numbering.

    See more

    Declaration

    Swift

    public protocol SequenceGenerator
  • An object capable of decoding attributes for use in NSAttributedString

    See more

    Declaration

    Swift

    public protocol AttributesDecoding
  • An object capable of decoding the given type of content into NSAttributedString for using in EditorView or the RendererView.

    See more

    Declaration

    Swift

    public protocol EditorContentDecoding
  • Identifies a content type within the Editor

    See more

    Declaration

    Swift

    public protocol EditorContentIdentifying
  • Undocumented

    See more

    Declaration

    Swift

    public protocol AttachmentTypeIdentifying
  • Describes a view contained in Attachment that contains a single EditorView. This is a helper protocol that can be applied to the view so that basic properties and functions are made available on the view as passthrough.

    See more

    Declaration

    Swift

    public protocol EditorContentView : Focusable
  • Describes an object interested in observing the bounds of a view. Attachment is BoundsObserving and reacts to changes in the bounds of views hosted within the Attachment. Any view contained in the Attachment that is capable of changing its bounds must define and set BoundsObserving to Attachment.

    Usage Example

     class MyAttachmentView: UIView {
     weak var boundsObserver: BoundsObserving?
    
     override var bounds: CGRect {
         didSet {
             guard oldValue != bounds else { return }
             boundsObserver?.didChangeBounds(bounds)
         }
        }
     }
    
     let myView = MyAttachmentView()
     let attachment = Attachment(myView, size: .matchContent)
     myView.boundsObserver = attachment
    
    See more

    Declaration

    Swift

    public protocol BoundsObserving : AnyObject
  • Describes an object interested in listening to events raised from EditorView

    See more

    Declaration

    Swift

    public protocol EditorViewDelegate : AnyObject
  • Describes a command that can be executed on EditorView. A command may be invoked directly on the editor by providing an instance. However, in a typical usage scenario, these should be invoked via EditorCommandExecutor which manages all the EditorViews in the view including the ones that are contained in the attachments.

    See more

    Declaration

    Swift

    public protocol EditorCommand : AnyObject
  • Undocumented

    See more

    Declaration

    Swift

    public protocol EditorCommandExecutorDelegate : AnyObject
  • Describes an encoder for a content type in Editor. This can be used in conjunction with AnyEditorTextEncoding to register various encoders for each of the supported content types. ### Usage Example ###

     struct ParagraphEncoder: EditorTextEncoding {
         func encode(name: EditorContent.Name, string: NSAttributedString) -> JSON {
             var paragraph = JSON()
             paragraph.type = name.rawValue
             if let style = string.attribute(.paragraphStyle, at: 0, effectiveRange: nil) as? NSParagraphStyle {
                 paragraph[style.key] = style.value
             }
             paragraph.contents = contentsFrom(string)
            return paragraph
         }
     }
    
    See more

    Declaration

    Swift

    public protocol EditorTextEncoding
  • Describes an object capable of encoding contents of at Attachment

    See more

    Declaration

    Swift

    public protocol AttachmentEncoding
  • An object capable of encoding EditorContent to given type.

    See more

    Declaration

    Swift

    public protocol 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())
    
    See more

    Declaration

    Swift

    public protocol EditorContentEncoder : EditorContentEncoding
  • An object capable of handing GridView events

    See more

    Declaration

    Swift

    public protocol GridViewDelegate : AnyObject
  • An object capable of handing TableView events

    See more

    Declaration

    Swift

    public protocol TableViewDelegate : AnyObject
  • An object capable of intercepting and modifying the text and attributes in an EditorView when registered with the EditorView.

    See more

    Declaration

    Swift

    public protocol TextProcessing