Search code examples
iosswiftswift3imessage

Why is Swift 3 code that's never executed throwing runtime errors?


I've been working on an iMessage extension using a tutorial from Apple's WWDC videos and encountered an strange error. I started with a blank project, which built an ran just fine. However, I added a file for my MSStickerBrowserViewController. The code built, but opening the extension in the simulator crashed it. The strange thing is, I never made an instance of the browser. Why would code that's not being executed crash?

Here's the error: dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib Referenced from: /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 Reason: image not found Here's the code triggering the error:

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 {

    }*/
}

I noticed if I take out line 16, which makes a URL, the error isn't thrown.

Here is the link to the WWDC video I followed. I've double checked to make sure I followed the video exactly


Solution

  • I reinstalled Xcode and it worked. Weird. Thanks for everyone's advice!