为什么Swift 3代码从未执行过抛出运行时错误?

时间:2016-07-08 21:41:40

标签: ios swift swift3 imessage

我一直在使用Apple的WWDC视频教程处理iMessage扩展,但遇到了一个奇怪的错误。我从一个空白的项目开始,这个项目很好。但是,我为MSStickerBrowserViewController添加了一个文件。代码已构建,但在模拟器中打开扩展程序会使其崩溃。奇怪的是,我从来没有制作过浏览器的实例。为什么代码没有被执行崩溃?

这里出现错误:dyld:未加载库:@ rpath / libswiftSwiftOnoneSupport.dylib   参考自:/Users/alextyshka/Library/Developer/CoreSimulator/Devices/BF34F16D-3CEF-4C7D-8D9A-D3D4B463F293/data/Containers/Bundle/Application/75E2E14B-E76B-4EC7-9528-7CE38864B55D/BlankMessages.app/PlugIns/ MessagesExtension.appex / MessagesExtension   原因:找不到图像 这是触发错误的代码:

import UIKit
import Messages

class MyStickerBrowserViewController: MSStickerBrowserViewController {
    var stickers = [MSSticker]()
    func changeBrowserViewBackgroundColor(color: UIColor) {
        stickerBrowserView.backgroundColor = color
    }
    func loadStickers() {
        createSticker(asset: "forest", localizedDescription: "forest sticker")
    }
    func createSticker(asset: String, localizedDescription: String) {
        guard let stickerPath = Bundle.main().pathForResource(asset, ofType: "png") else {
            print("couldn't create the sticker path for", asset)
            return
        }
        let stickerURL = URL(fileURLWithPath: stickerPath) //This is the line that seems to be causing the error. 
        let sticker: MSSticker
        do {
            try sticker = MSSticker(contentsOfFileURL: stickerURL, localizedDescription: localizedDescription)
            stickers.append(sticker)
            } catch {
                print(error)
            return
        }
    }
    /*
    override func numberOfStickers(in stickerBrowserView: MSStickerBrowserView) -> Int {

    }

    override func stickerBrowserView(_ stickerBrowserView: MSStickerBrowserView, stickerAt index: Int) -> MSSticker {

    }*/
}

我注意到如果我从第16行取出一个URL,则不会抛出错误。

Here是我遵循的WWDC视频的链接。我已仔细检查以确保我完全按照视频

1 个答案:

答案 0 :(得分:0)

我重新安装了Xcode并且工作正常。奇怪的。感谢大家的建议!