2

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

A Tyshka
  • 3,830
  • 7
  • 24
  • 46
  • You may want to try adding an exception breakpoint to see where exactly the problem is, so we get a better idea of what the error could be. – vigneshv Jul 08 '16 at 21:44
  • I've used breakpoints. The error is getting thrown early, before `willBecomeActive` or `viewDidLoad` – A Tyshka Jul 08 '16 at 21:48
  • The user in [this](http://stackoverflow.com/questions/37820755/running-spritekit-game-in-watchos-on-apple-watch-simulator-xcode-8-swift-3-io) question had the same error on an Apple Watch app, but that solution didn't work for me. – A Tyshka Jul 08 '16 at 21:50
  • 4
    Before your program starts executing, the dynamic linker (dyld) looks at the external libraries that your program needs and loads them. If it can't, it aborts execution. This is why merely referencing code or data from another library may cause your program to fail. There are tools that let you see what your program needs a library for (though I don't know their invocation off my head and I'm not in front of a Mac right now); my guess is that your program references class metadata. – zneak Jul 08 '16 at 22:40
  • Thanks. I'm using Apple's Messages framework. Nothing 3rd party so that's weird. I'm updating my post with the problematic code if that helps – A Tyshka Jul 09 '16 at 03:09
  • Did you look at the error message? It's a Swift support lib that is not found. Most likely a tools issue. Make sure to open a bug report with Apple. https://bugreport.apple.com – Léo Natan Jul 09 '16 at 20:04
  • I thought it might be a bug. Thanks Leo. – A Tyshka Jul 09 '16 at 20:18
  • @Leo Natan Should I file it as a bug with Xcode or a bug with iOS? – A Tyshka Jul 09 '16 at 20:23
  • Seems to me like Xcode (developer tools) are not embedding all necessary libs with bundle. In the meantime, you can use the simulator to test your Messages app. – Léo Natan Jul 09 '16 at 20:25
  • @Leo Natan No it's crashing in the simulator – A Tyshka Jul 09 '16 at 20:25
  • I don't have a device with iOS 10 beta – A Tyshka Jul 09 '16 at 20:26
  • Now that is major strange. Wait for a later beta, I guess. – Léo Natan Jul 09 '16 at 20:57
  • How come no one else making iMessage apps is having this problem. Maybe reinstall Xcode? – A Tyshka Jul 09 '16 at 23:48
  • I looked through the release notes for beta 2. It said "Making code changes to a Swift project and building does not result in a binary that fails to run and errors about “dyld: Library not loaded”. (26532737)" Supposedly they fixed a problem but perhaps they created one? – A Tyshka Jul 10 '16 at 00:40
  • Have you tried cleaning & rebuilding? – jtbandes Jul 10 '16 at 00:57
  • Cleaning? What's that? – A Tyshka Jul 10 '16 at 18:22

1 Answers1

0

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

A Tyshka
  • 3,830
  • 7
  • 24
  • 46