iosswiftimagesvgkit

App Crashing as *** Assertion failure in +[SVGKImage imageWithSource:]


I am working with SVGKit in swift Project. I properly imported SVGKit Framework and 3rd party resources folder into my project by following (https://github.com/SVGKit/SVGKit).

I created a folder with sets of .svg images inside the project and i am using the following code to load image into testIcon(ImageView).

let lockImage: SVGKImage = SVGKImage(named: "LockIcon.svg")
let lockImageLocal: UIImage = lockImage.uiImage
testIcon.image = lockImageLocal

But i am receiving the following error,

** Assertion failure in +[SVGKImage imageWithSource:], /Users/fss/Downloads/SVGKit- 2.x/Source/SVGKImage.m:229

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: newSource != nil'

Please let me know how to mention path of .svg image(which is inside my project) to SVGKImage image class or how to resolve this problem.


Solution

  • please remove .svg from image name. This method named: doesn't need extension.

    Or you can try this way too...

    Swift 4

    if let imagePath = Bundle.main.path(forResource: "imageName", ofType: "svg")     
    {
      let lockImage: SVGKImage = SVGKImage(contentsOfFile: imagePath)
      let lockImageLocal: UIImage = lockImage.uiImage
      testIcon.image = lockImageLocal
    }
    

    Obj-c type

    NSString *imagePath = [NSBundle mainBundle][ pathForResource:@"imageName" ofType:@"svg"];
    UIImage *image = [UIImage imageWithContentsOfFile:imagePath];