handzel
handzel

Reputation: 91

Custom init with id to ViewController in Objective-C from Swift code

I need help you with convert my Swift code to Objective-c.

There is my Swift code.

 self.show(ChatViewController(conversation: conversation!), sender: self)

I have no idea how to convert them to with init "conversation". This is Id of conversation for my chat in Socket.

 ChatViewController *chatVC = [[ChatViewController alloc] init];
            [vc showViewController: chatVC sender:self];

Upvotes: 1

Views: 887

Answers (3)

Max
Max

Reputation: 22365

All Swift stuff must be marked @objc public to be visible in Objective-C. In this case that would be the ChatViewController class, its init(conversation:), and whatever the conversation type is.

If you do that correctly, Objective-C should be able to import your generated interface header (find this in your build settings, it usually looks like "AppName-Swift.h").

Then the Swift methods would be automatically converted to Objective-C style methods so you would be able to call

ChatViewController *chatVC = [[ChatViewController alloc] initWithConversation:converstaion];

Upvotes: 1

Asperi
Asperi

Reputation: 258137

It is not clear what conversation type is, but swift constructor

ChatViewController(conversation: conversation!)

in Objective-C is

ChatViewController *chatVC = [[ChatViewController alloc] 
    initWithConversation:conversation];

Upvotes: 0

petrhung9
petrhung9

Reputation: 91

May be Swift can't bridge your conversation object

Upvotes: 0

Related Questions