1

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];

3 Answers 3

1

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];
Sign up to request clarification or add additional context in comments.

Comments

0

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

ChatViewController(conversation: conversation!)

in Objective-C is

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

Comments

0

May be Swift can't bridge your conversation object

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.