قالب وردپرس درنا توس
Home / IOS Development / ios – Fatal error: Use of unimplemented initializer & # 39; init () & # 39; for class swift

ios – Fatal error: Use of unimplemented initializer & # 39; init () & # 39; for class swift



I use MarkdownTextView to add basic markdown to a UITextView . TextView is a subclass of MarkdownTextView .

But when using copy and paste, I get the following error

Fatal error: Using unimplemented initializer & # 39; init () & # 39; for the class
MarkdownTextStorage

How to use TextStorage in ViewController

  easy fonty = UIFont (name: font, size: fsize)

attributes.defaultAttributes [NSFontAttributeName] = fonty
attributter.orderedListAttributes? [NSFontAttributeName] = fonty
attributter.orderedListItemAttributes? [NSFontAttributeName] = fonty
attributes.unorderedListAttributes? [NSFontAttributeName] = fonty
attributes.unorderedListItemAttributes? [NSFontAttributeName] = fonty

let tekstStorage = MarkdownTextStorage (attributes: attributes)

do {
textStorage.addHighlighter (try LinkHighlighter ())
} make mistakes {
fatalError ("Incorrect initialization LinkHighlighter:  (error)")
}
textStorage.addHighlighter (MarkdownStrikethroughHighlighter ())
textStorage.addHighlighter (MarkdownSuperscriptHighlighter ())

whose let codeBlockAttributes = attributes.codeBlockAttributes {
textStorage.addHighlighter (MarkdownFencedCodeHighlighter (attributes: codeBlockAttributes))
}

I have used the following initializes, but still have no luck

  required public init? (Codes aDecoder: NSCoder) {
attributes = MarkdownAttributes ()
super.init (encoder: aDecoder)
commonInit ()
}

Here is the full source code for the class

  open class MarkdownTextStorage: HighlighterTextStorage {

fileprivate la attributes: MarkdownAttributes

// MARK: Initialization

/ **
Creates a new instance of the recipient.

: param: attributes Attributes used to style the text.

: Return: An initialized instance of `MarkdownTextStorage`
* /
public init (attributes: MarkdownAttributes = MarkdownAttributes ()) {
self.attributes = attributes
super.init ()
commonInit ()

if la headerAttributes = attributes.headerAttributes {
addHighlighter (MarkdownHeaderHighlighter (attributes: headerAttributes))
}
addHighlighter (MarkdownLinkHighlighter ())
addHighlighter (MarkdownListHighlighter (markerPattern: "[*+-]", attributes: attributes.unorderedListAttributes, itemAttributes: attributes.unorderedListItemAttributes))
addHighlighter (MarkdownListHighlighter (cursorPattern: "\ d + [.]", attributes: attributes.orderedListAttributes, itemAttributes: attributes.orderedListItemAttributes))

// From markdown.pl v1
.0.1 // Codeblocks ? AddPattern ("(: n n | \ A) ((: (?:?.? [ ] {4} | t) * n +) +) ({^ ^ [ ] {0, 4} \ S) | \ Z) ", attributter.codeBlockAttributes) // Block quotes addPattern ("(?: ^ [ t] *> [ t]?. + n (. + n) * n *) +" attributes.blockQuoteAttributes) // Se-text style headings // H1 addPattern ("^ (?:. +) [ t] * n = + [ t] * n +", attributes.headerAttributes? .h1Attributes) // H2 addPattern ("^ (?:. +) [ t] * n - + [ t] * n +" attributes.headerAttributes? .h2Attributes) // Weighting addPattern ("(\ * | _) (? = \ S) (. +?) (? <= \ S) \ 1", attributesForTraits (.traitItalic, attributes.emphasisAttributes)) // Strong Add thePattern ("(\ * \ * | __) (? = \ S) (?:. +? [*_] *) (? <= \ S) \ 1", attributesForTraits (.traitBold, attributes .strongAttributes)) // Inline code addPattern ("(` +) (?:. +?) (? TextAttributes? { var attributes = attributes if left defaultFont = defaultAttributes [NSFontAttributeName] as? UIFont, attributes == nil { attributes = [ NSFontAttributeName: fontWithTraits(traits, font: defaultFont) ] } return attributes }

]

Full Error Screenshot

 Enter image description here

Does anyone have any suggestions on how to solve the problem?


Source link