Search code examples
iossocket.ioobjective-c-swift-bridge

importing swift file to obj-c


Okay, this one is too much for me. I'm trying to import manually file from socket-io which are written in swift, to my project who is fully written in obj-c.

I have read the doc from Swift and obj-c, but that's not really helpful at all. And from socket-io, same thing. All it says is to download the github project, import the "source" folder to my obj-c project, and then follow the instruction from Apple doc which to my opinion are definitively not clear at all.

My question is: what is the concept of swift module? Because I definitively didn't found what conceptually is a module, and how to build it from a folder of swift file, even if I think it is a collection of swift class, but with Apple, I'm not even sure of this.

my project is structured like this:

.
+-- projectName
+-- Source
|   +-- SockectFile_0.swift
|   +-- SockectFile_1.swift
|   +-- SockectFile_2.swift
|   +-- SockectFile_3.swift

+-- ViewController
|   +-- viewController_0.h
|   +-- viewController_0.m

Then how to import the whole "Source" folder with all this files inside to my viewController_0.m ? I don't have even any idea how to compile it as a module. Or if it is the right way to do it. Like I said, I'm in a confused state right now.

Thanks for the answers in advance.

Note After further research, I have give it up. What I did is compile the entire swift project alone and import it as framework. But of course, it is too much for Xcode to handle the framework as a fat binary. Sorry if I look gross, but I don't understand why Xcode is a sooooooooooo bad IDE tool. For info, it took me approximatively 1 minute to import socketIO in my python project where it took me 3 hours with Xcode with the source code, and I just dodged the problem because what I did is the binary solution (Xcode is even not good at making a simple fat binary by itself. Where it took 3 lines of script to implement). I really hate.


Solution

  • Making Swift Module

    You have to follow these steps Goto Build Setting > Search = Defines Module to YES then > Search product module name and give name for your Module there enter image description here

    Then

    enter image description here

    Your Can use your Module Like @import MQTTKit;

    enter image description here