External library usage in xcode

2019-06-02 21:24发布

问题:

I am following this tutorial for import socket.io to swift. http://socket.io/blog/socket-io-on-ios/

I did everything in the tutorial but I am getting this error:

Use of unresolved identifier 'SocketIOClient'

for this piece of code:

let socket = SocketIOClient(socketURL: "localhost:8900") 

My structure:

How can I resolve this problem ?

回答1:

make sure about 2 things:

  • select "create groups" not "create folder references"
  • copy items if needed


回答2:

In the bridging-header.h change this #import "SocketRocket/SRWebSocket.h" to this:

#import <SocketRocket/SRWebSocket.h>

If it does not work just add:

#import "SRWebSocket.h"

Also rename yout bridging header to Ribony-Bridging-Header.h and add it your project's target settings (refer to your bridging header path not just copy "TicTacIOiOS/Bridging-Header.h" from the documentation for websockets).



回答3:

Make sure when copying you actually are copying the files. Here's a screen shot showing what I mean.

Don't do this when copying files...

In this image the options "Copy items if needed is deselected"

But be sure to do this

Select the option "Copy items if needed"

Also be sure to build your project after importing into the Bridging Header file. Be sure if it is a framework to import like so

#import <Framework/Framework.h>

But if it is a stand alone .h file then import it like so

#import "MyClass.h" 

UPDATE: I would also suggest having a look here to make sure you got the steps right - How to call Objective-C code from Swift