1

For rendering svg file on iPhone I have downloaded a project from GitHub SVGQuartzRenderer but it shows the following errors:

  1. UIKit/UIKit.h No such file or directory (I am not able to add it using add existing frameworks)
  2. Libxml/tree.h:No such file or directory
  3. Expected specifier-qualifier list before xmlParserCtxtPtr

Does anyone know how I can make this project work?

I have also found another framework: SVGKit. It works well for some SVG files but not for all.

Is it possible to render any SVG file in iPhone without using UIWebView and are there any tutorials or sample code?

Chris
  • 4,009
  • 3
  • 21
  • 52
nehal
  • 297
  • 2
  • 5
  • 12
  • Have you added the UIKit framework to the project? Go to the project settings, build phases, link with frameworks and add it. Make sure the target SDK is iOS. – Greg Jul 08 '11 at 12:37
  • It would be useful if you could provide an example of an SVG file which SVGKit does not render. – jbeard4 Jul 09 '11 at 00:00
  • while testing this file it just renders one circle – nehal Jul 09 '11 at 07:19
  • @night leopard:after adding uikit framework it shows the error that No such file or directory.i think this is project for mac os.But on the instruction page of this project it is written that it works for iphone – nehal Jul 09 '11 at 07:25
  • @echo-flow 1)http://coveredincake.com/svgfiles/cupcakewrapper.svg the svg file of this url also does not work it shows error 2)http://www-archive.mozilla.org/projects/svg/lion.svg while in this second error image is not rendered properly – nehal Jul 09 '11 at 07:28
  • @nehal go to the build settings and set the base sdk to iOS, and make sure `architectures` is set to `armv6 armv7` and `valid architectures` is set to `armv6 armv7 i386`. I think the problem is not so much with the svg as the project settings. – Greg Jul 09 '11 at 08:05

1 Answers1

2

Starting Xcode 12, you can add the .svg file in your Assets Catalog and do this:

let image = UIImage(named: "SomeSVGImage")

ref: https://developer.apple.com/documentation/xcode-release-notes/xcode-12-beta-release-notes

Ted
  • 22,696
  • 11
  • 95
  • 109
  • This is working. However, take care, with XCode 13.2 (and I guess earlier version), if the SVG file you add in the asset contains some blured element, XCode will a) not compile b) crash when you try to show the SVG image in the asset editor (though the file shows correctly in the editor). – AirXygène Mar 05 '22 at 11:49