NSXMLSVGParser

open class NSXMLSVGParser : XMLParser, XMLParserDelegate

Concrete implementation of SVGParser that uses Foundation’s XMLParser to parse a given SVG file.

  • Error type used when a fatal error has occured

    Declaration

    Swift

    enum SVGParserError
  • The SVGLayer that will contain all of the SVG’s sublayers

    Declaration

    Swift

    open var containerLayer: SVGLayer
  • Convenience initializer that can initalize an NSXMLSVGParser using a local or remote URL

    Declaration

    Swift

    public convenience init(svgURL: URL, supportedElements: SVGParserSupportedElements? = nil, completion: ((SVGLayer) -> ())? = nil)

    Parameters

    svgURL

    The URL of the SVG.

    supportedElements

    Optional SVGParserSupportedElements struct that restrict the elements and attributes that this parser can parse.If no value is provided, all supported attributes will be used.

    completion

    Optional completion block that will be executed after all elements and attribites have been parsed.

  • Initializer that can initalize an NSXMLSVGParser using SVG Data

    Declaration

    Swift

    public required init(svgData: Data, supportedElements: SVGParserSupportedElements? = SVGParserSupportedElements.allSupportedElements, completion: ((SVGLayer) -> ())? = nil)

    Parameters

    svgURL

    The URL of the SVG.

    supportedElements

    Optional SVGParserSupportedElements struct that restricts the elements and attributes that this parser can parse. If no value is provided, all supported attributes will be used.

    completion

    Optional completion block that will be executed after all elements and attribites have been parsed.

  • Starts parsing the SVG document

    Declaration

    Swift

    public func startParsing()
  • The XMLParserDelegate method called when the parser has started parsing an SVG element. This implementation will loop through all supported attributes and dispatch the attribiute value to the given curried function.

    Declaration

    Swift

    open func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String])
  • The XMLParserDelegate method called when the parser has ended parsing an SVG element. This methods pops the last element parsed off the stack and checks if there is an enclosing container layer. Every valid SVG file is guaranteed to have at least one container layer (at a minimum, a SVGRootElement instance).

    If the parser has finished parsing a SVGShapeElement, it will resize the parser’s containerLayer bounding box to fit all subpaths

    If the parser has finished parsing a <svg> element, that SVGRootElement‘s container layer is added to this parser’s containerLayer.

    Declaration

    Swift

    open func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?)
  • The XMLParserDelegate method called when the parser has finished parsing the SVG document. All supported elements and attributes are guaranteed to be dispatched at this point, but there’s no guarantee that all elements have finished parsing.

    See also

    CanManageAsychronousParsing finishedProcessing(shapeLayer:)

    Declaration

    Swift

    public func parserDidEndDocument(_ parser: XMLParser)
  • The XMLParserDelegate method called when the parser has reached a fatal error in parsing. Parsing is stopped if an error is reached and you may want to check that your SVG file passes validation.

    See also

    XMLParserDelegate (parser(_:parseErrorOccurred:))[https://developer.apple.com/documentation/foundation/xmlparserdelegate/1412379-parser]

    See also

    (SVG Validator)[https://validator.w3.org/]

    Declaration

    Swift

    public func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error)
  • Method that resizes the container bounding box that fits all the subpaths.

    Declaration

    Swift

    func resizeContainerBoundingBox(_ boundingBox: CGRect?)