Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using socket.io-client-swift in an Objective-C framework. #393

Closed
hifall opened this issue Jun 13, 2016 · 13 comments
Closed

Using socket.io-client-swift in an Objective-C framework. #393

hifall opened this issue Jun 13, 2016 · 13 comments
Labels

Comments

@hifall
Copy link

hifall commented Jun 13, 2016

Hi,

We are trying to integrate your socket.io-client-swift library into our existing Objective-C framework which will be released to other developers to integrate into their applications.

Is this scenario considered when you develop socket.io-client-swift? Is there anything special (compared with integrating socket.io-client-swift into an app) we need to consider?

Thanks!

@nuclearace
Copy link
Member

I'm not sure. I know there's some problem where you can't make it a static framework.

@hifall
Copy link
Author

hifall commented Jun 13, 2016

Right. In Xcode 7.3, after I added the swift files and tried to compiled my framework, it errored: Swift is not supported for static libraries.

But maybe we can compile your lib into a framework first, then link to it? Haven't tried that yet. Just a thought.

@drekka
Copy link
Contributor

drekka commented Jun 14, 2016

@hifall Change your build target from a static library to a framework. You can then use socket.io in it without issues. You can also build socket.io as a framework as import that. In my project I'm building socket.io and other frameworks using carthage without issues.

@hifall
Copy link
Author

hifall commented Jun 15, 2016

@drekka, thanks for the hint. But any chance you could provide a bit more detail on "Change your build target from a static library to a framework", or provide any pointer to it? I am building my framework following this link: https://github.com/jverkoey/iOS-Framework.

Thanks!

@drekka
Copy link
Contributor

drekka commented Jun 15, 2016

Whoa. That information is really out of date - don't do that :-)

Building a framework these days is dead simple. In Xcode add a new target using the Framework & Library/Cocoa Touch Framework template. Then just add your code like you would for a static library. XCode will build a *.framework file ready for use.

I did a quick search and found this article: https://robots.thoughtbot.com/creating-your-first-ios-framework It seems to be very good in that it shows how easy it is, then goes on to handling dependencies, CocoaPods and Carthage support, and testing. Pretty much everything you would do as part of building an API.

@hifall
Copy link
Author

hifall commented Jun 15, 2016

@drekka, thanks for getting back to me! I am indeed not up to date on iOS framework building these days. I will definitely do some research in this area by following your link shortly.

Again, thanks for the link.

@bhartsb
Copy link

bhartsb commented Jun 21, 2016

I too am trying to get this library working from Objective-C. I've added a framework, added the swift source files, and built the framework. I shouldn't need to add @objc to the class as it is already inheriting from NSObject. The documentation herein regarding this seems to be missing some steps.

@drekka
Copy link
Contributor

drekka commented Jun 22, 2016

Hi @bhartsb - it sounds like you are using socket.io from Swift. Which class are you adding @objc to?

@bhartsb
Copy link

bhartsb commented Jun 22, 2016

I have an objective c project that I want to use the swift library in. I found out that there's a auto generated bridging header file that I have to include in my objective-C file that I want to use this swift library from. Not withstanding I'm not sure that this is even the correct library to use since I'm using websockets.I saw other issues where another library for specifically websockets was being mentioned.

On Jun 21, 2016, at 6:31 PM, Derek Clarkson notifications@github.com wrote:

Hi @bhartsb - it sounds like you are using socket.io from Swift. Which class are you adding @objc to?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@drekka
Copy link
Contributor

drekka commented Jun 22, 2016

ok. Can't speak for web sockets, but here is basically what I did to use the socket.io framework:

  1. Build the socket.io/socket.io-client-swift project using carthage.

    1. Add github "socketio/socket.io-client-swift" to my project's Cartfile.
    2. Run carthage update
  2. Add the resulting framework into my project as I would for any other framework.

  3. Add an import:

    #import <SocketIOClientSwift/SocketIOClientSwift-Swift.h>
    
  4. Instantiate socket:

    SocketIOClient *socket = [[SocketIOClient alloc] initWithSocketURL:_serverURL options:@{@"log":@YES}];
    // Configure the socket ...
    

Hope that helps.

@bhartsb
Copy link

bhartsb commented Jun 22, 2016

Thanks!

Sent from my iPhone

On Jun 21, 2016, at 6:59 PM, Derek Clarkson notifications@github.com wrote:

ok. Can't speak for web sockets, but here is basically what I did to use the socket.io framework:

Build the socket.io/socket.io-client-swift project using carthage.

Add github "socketio/socket.io-client-swift" to my project's Cartfile.

Run carthage update

Add the resulting framework into my project as I would for any other framework.

Add an import:

#import <SocketIOClientSwift/SocketIOClientSwift-Swift.h>
Instantiate socket:

SocketIOClient *socket = [[SocketIOClient alloc] initWithSocketURL:_serverURL options:@{@"log":@yES}];
// Configure the socket ...
Hope that helps.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@b9AobJ
Copy link

b9AobJ commented Dec 12, 2016

why have not oc,if use swift to create static framework,it will be add libSwiftBridge.a,has 100M+

@ZvOlCuOk2009
Copy link

ZvOlCuOk2009 commented Dec 26, 2017

@drekka I'm adding a dependency, and get the following error:

*** Building scheme "Starscream" in Starscream.xcodeproj
Build Failed
Task failed with exit code 65:
/usr/bin/xcrun xcodebuild -project /Users/admin/Test\ Tiras/Carthage/Checkouts/Starscream/Starscream.xcodeproj -scheme Starscream -configuration Release -derivedDataPath /Users/admin/Library/Caches/org.carthage.CarthageKit/DerivedData/8.3.2_8E2002/Starscream/3.0.3 -sdk watchos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES archive -archivePath /var/folders/2r/nmnc_7gx06j5b51q854nm48h0000gn/T/Starscream SKIP_INSTALL=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=NO CLANG_ENABLE_CODE_COVERAGE=NO (launched in /Users/admin/Test Tiras/Carthage/Checkouts/Starscream)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants