Swiftmessages: swift messages error

Created on 5 Oct 2017  Â·  16Comments  Â·  Source: SwiftKickMobile/SwiftMessages

@srstanic @defagos @raven @qx89l4 @triskybro I updated this project using cocoapods to the latest version after upgrading to xcode 9. I use swiftmessages all over my project and this is by far the best alert I've ever seen. The old version worked perfectly but this version crashes when I try to display the alert. can you help me. I think there is a bug in this project.

Most helpful comment

I'm seeing this crash as well. It crashes since following line returns nil and is force unwrapped.
UIImage(named: rawValue, in: Bundle.sm_frameworkBundle(), compatibleWith: nil)

I'm using Xcode 9 and iPhone 8 - iOS 11.0 simulator. Cocoapod version 1.3.1.
I tried reproducing using the demo project as well as by using the pod in a single view new sample project. It didn't crash!
Not sure what is wrong here! Is it possible Xcode doesn't recognises images from Asset catalog for some reasons?

All 16 comments

Please provide the relevant code and the crash log.

I've same error. In my case, the crash is on Theme.swift line 37.
I think that the path of the images are wrong and return a nil UIImage.

    /// Returns the associated image.
    public var image: UIImage {        
        return UIImage(named: rawValue, in: Bundle.sm_frameworkBundle(), compatibleWith: nil)!
    }

Does the demo project work?

I didn't use the demo project I just upgraded my car

On Thursday, October 5, 2017, Timothy Moose notifications@github.com
wrote:

Does the demo project work?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/SwiftKickMobile/SwiftMessages/issues/128#issuecomment-334529410,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOS4XnLALI4VF9DOdZFvRVSBx8zaq_cRks5spQx8gaJpZM4PvUkC
.

I'm asking you and/or @logicsb to test the demo project and tell me if it works.

It doesn't crash for me, so I'm going to need you to work with me to figure out what's going on. I can't do anything with the limited amount of information you've given me so far.

  1. Whats the stack trace?
  2. What device or simulator are you using?
  3. What Xcode build are you using?
  4. What version of CocoaPods are you using?
  5. Have you tried deleting your derived data?
  6. Have you tried reinstalling pods?
  7. What does your SwiftMessages code look like?
  8. Can you send me a sample project that crashes?

I'm seeing this crash as well. It crashes since following line returns nil and is force unwrapped.
UIImage(named: rawValue, in: Bundle.sm_frameworkBundle(), compatibleWith: nil)

I'm using Xcode 9 and iPhone 8 - iOS 11.0 simulator. Cocoapod version 1.3.1.
I tried reproducing using the demo project as well as by using the pod in a single view new sample project. It didn't crash!
Not sure what is wrong here! Is it possible Xcode doesn't recognises images from Asset catalog for some reasons?

@ajithrnayak The original poster hasn't provided a stack trace, so I have no reason to believe that you are seeing the same crash.

But, I suggest clearing your derived data and doing a pod install. If it still crashes, grab the SwiftMessages.framework file out of the derived data and attach it here so I can take a look.

@wtmoose Here's the stack trace

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x000000011243a060 libswiftCore.dylib`function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage(Swift.StaticString, Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 96
  * frame #1: 0x000000010eed1126 SwiftMessages`Icon.image.getter(self=info) at Theme.swift:37
    frame #2: 0x000000010eed4e54 SwiftMessages`IconStyle.image(theme=info, self=default) at Theme.swift:52
    frame #3: 0x000000010eea28fc SwiftMessages`MessageView.configureTheme(theme=info, iconStyle=default, self=0x00007f980af04e50) at MessageView.swift:256
    frame #4: 0x000000010735f884 App-Dev`StatusBanner.showBanner(config=App_Dev.StatusBannerConfig @ 0x00007fff58f1d230, tapHandler=nil, self=0x00007f9811916a00) at StatusBanner.swift:73
    frame #5: 0x000000010724b9cb App-Dev`BlueprintEditorViewController.showAlertBanner(message="In order to get started you need to create or select a report above", autoHide=true, self=0x00007f9811916a00) at BlueprintEditorViewController.swift:581

I suggest clearing your derived data and doing a pod install
Tried it before posting. Also, updated to latest release version. I made a hot fix by setting iconStyle to none.

Attaching the SwiftMessages.framework file here.
SwiftMessages.framework.zip

It seems that it's all related: #96, #12, #31, #55, #9. I have the same problem. It crashes with _Could not load the "errorIcon" image referenced from a nib in the bundle with identifier "org.cocoapods.SwiftMessages"_ on _return UIImage(named: rawValue, in: Bundle.sm_frameworkBundle(), compatibleWith: nil)!_
My device is not jailbroken, Xcode 9.0.1 (9A1004), Cocoapods 1.2 (I use Cocoapods app).

@woyhat @ajithrnayak could one of you guys step through the sm_frameworkBundle and tell me which line it returns on? It would be helpful to know if the correct bundle is being found. (It should return on line 15 for a CocoaPods install).

@woyhat @ajithrnayak I have created a branch work/assets with errorIcon moved out of the asset catalog. If someone can validate both of the following test scenarios, I will move all assets out of the catalog:

  1. Verify that the statement Icon.error.image DOESN'T crash the app.
  2. Verify that the statement Icon.warning.image DOES crash the app.

@wtmoose yes, correct bundle is being found - SwiftMessages.bundle at if let on line 15. And yes, the branch fixes the crash, as errorIcon can be found in SwiftMessages.bundle directly. It doesn't find warningIcon in SwiftMessages.bundle/Assets.car. Any ideas why?

@woyhat I don't know. You can try running this from your bundle folder and see if the images are there:

xcrun --sdk iphoneos assetutil --info Assets.car

I did this for the framework attached above and errorIcon is there. So my best guess is it's either caused by certain project configurations or an iOS bug.

Fix on head of master if anyone wants to verify.

As expected it fixes the issue. I've just verified it by switching between 4.0.0 and 4.0.1.

Fixed in 4.1.0 release

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lohenyumnam picture lohenyumnam  Â·  3Comments

JanBrinker picture JanBrinker  Â·  6Comments

andrey-zelenin picture andrey-zelenin  Â·  4Comments

H-Ghadirian picture H-Ghadirian  Â·  6Comments

X901 picture X901  Â·  5Comments