【问题标题】:App Crashing as *** Assertion failure in +[SVGKImage imageWithSource:]应用程序崩溃为 *** +[SVGKImage imageWithSource:] 中的断言失败
【发布时间】:2018-02-20 08:13:25
【问题描述】:

我正在 swift Project 中使用 SVGKit。我按照 (https://github.com/SVGKit/SVGKit) 将 SVGKit 框架和第 3 方资源文件夹正确导入到我的项目中。

我在项目中创建了一个包含多组 .svg 图像的文件夹,我正在使用以下代码将图像加载到 testIcon(ImageView) 中。

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

但我收到以下错误,

** +[SVGKImage imageWithSource:], /Users/fss/Downloads/SVGKit-中的断言失败 2.x/Source/SVGKImage.m:229

*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效参数不是 令人满意:newSource != nil'

请告诉我如何将.svg 图像(在我的项目中)的路径提及到 SVGKImage 图像类或如何解决此问题。

【问题讨论】:

    标签: ios swift image svgkit


    【解决方案1】:

    请从图像名称中删除.svg。这个方法named:不需要扩展。

    或者你也可以试试这个方法……

    斯威夫特 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 类型

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-01
      • 2017-04-24
      • 1970-01-01
      • 2012-12-31
      相关资源
      最近更新 更多