iOS Question iSVG: how to initialize from an XML-formatted string in memory?


Licensed User
Longtime User
I'm wondering if it is possible to initialize it from a XML-formatted string in memory, as it is done with B4A's SVG.initialize3(svgString as String)

Current iSVG lib allows initialization from a file, but not more.
I think SVGKit allows it, but I'm not expert with OBJC and also don't know if it would be possible

The reason is that I must edit its content quite often, and I'd like to avoid the process of:
  • read file contents as string
  • edit contents
  • save file
  • initialize SVG with that file

Any hint/idea if it is possible using nativeObject/ObjC ?

Thanks in advance


B4X founder
Staff member
Licensed User
Longtime User
Try this method:
Sub CreateSVGFromString (s As String) As SVG
   Dim no As NativeObject
   Dim source As NativeObject
   source = source.Initialize("SVGKSourceNSData").RunMethod("sourceFromData:URLForRelativeLinks:", Array(source.ArrayToNSData(s.GetBytes("UTF8")), Null))
   Return no.Initialize("SVGKImage").RunMethod("imageWithSource:", Array(source))
End Sub

Note that it sets the base url to Null. This could break SVGs with relative paths.
Upvote 0