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
-
Convenience initializer that can initalize an
NSXMLSVGParser
using a local or remoteURL
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 SVGData
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, aSVGRootElement
instance).If the parser has finished parsing a
SVGShapeElement
, it will resize the parser’scontainerLayer
bounding box to fit all subpathsIf the parser has finished parsing a
<svg>
element, thatSVGRootElement
‘s container layer is added to this parser’scontainerLayer
.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
XMLParserDelegate
(parserDidEndDocument(_:)
)[https://developer.apple.com/documentation/foundation/xmlparserdelegate/1418172-parserdidenddocument]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?)
-
The
CanManageAsychronousParsing
callback called when anParsesAsynchronously
element has finished parsingDeclaration
Swift
func finishedProcessing(_ shapeLayer: CAShapeLayer)