Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make accessible from Objective-C code #41

Closed
mattem86 opened this issue Dec 1, 2016 · 4 comments
Closed

Make accessible from Objective-C code #41

mattem86 opened this issue Dec 1, 2016 · 4 comments

Comments

@mattem86
Copy link

mattem86 commented Dec 1, 2016

I haven't managed to get it used by ObjC code...

@wtmoose
Copy link
Member

wtmoose commented Dec 1, 2016

SwiftMessages uses data structures that can't be seen by Objective-C. So it isn't possible. What you can do is write your own helper function in Swift that can be seen by Objective-C and call that:

func showErrorMessage(title: String, subtitle: String) {
    // show message here
}

@goodstechinc
Copy link

@mattem86 Can you explain how you made this work?

@mattem86
Copy link
Author

mattem86 commented Jun 2, 2017

Hi, yes of course:

I made a class "Messenger" in Swift:

import Foundation
import UIKit
import SwiftMessages

let status2 = MessageView.viewFromNib(layout: .StatusLine)

open class Messenger : NSObject {
    open class func showStatusBarMessage(_ msg: String, color: UIColor, sender: UIViewController) {
        status2.backgroundView.backgroundColor = color
        status2.bodyLabel?.textColor = UIColor.white
        status2.configureContent(body: msg)
        var status2Config = SwiftMessages.defaultConfig
        status2Config.preferredStatusBarStyle = UIStatusBarStyle.lightContent
        status2Config.duration = .forever
        status2Config.presentationContext = .automatic

        SwiftMessages.show(config: status2Config, view: status2)
    }
}

and call it from my Objective-C class like (of course I have to #import my "Module"-Swift.h in it):

[Messenger showStatusBarMessage:@"Blabla" color:[UIColor colorWithRed:0.25 green: 0.43 blue: 0.10 alpha:1.0] sender:self];

Hope this helps...!

@codaman
Copy link

codaman commented Dec 28, 2019

You have to add "@objc" start of method

@objc
open class func showStatusBarMessage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants