External library usage in xcode

2019-06-02 21:01发布

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:

enter image description here

How can I resolve this problem ?

3条回答
时光不老,我们不散
2楼-- · 2019-06-02 21:16

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...

Remember to click "Copy items if needed" and in some cases "Create Groups"

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

But be sure to do this

enter image description here

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

查看更多
地球回转人心会变
3楼-- · 2019-06-02 21:28

make sure about 2 things:

  • select "create groups" not "create folder references"
  • copy items if needed
查看更多
孤傲高冷的网名
4楼-- · 2019-06-02 21:29

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).

enter image description here

查看更多
登录 后发表回答