2

I'm trying to create a swift program that uses sockets. In order to do that, I'm trying to use the SwiftSocket library by installing it using CocoaPods. My Podfile is basic:

target 'socket' do
    # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
    use_frameworks!

    # Pods for socket
    pod 'SwiftSocket' 
end

According to the installation guide of SwiftSocket, after installing the pod I should be able to use the TCPClient right away. Still, I fail to use the class in my main.swift file as it doesn't find the class. I've searched the web to see what I'm missing here, but all I found are guides on how to bridge Pods written in ObjectiveC but not on pods written in Swift.

Any help? Thanks

EDIT: With jamshes reginahit suggestion, I've added SwiftSocket.framework to the Linked Frameworks and Libraries, in addition to the Pods_socket framework that was already present. Now the build is successful, but I gut a runtime error of Thread1: signal SIGABRT with the payload:

yld: Library not loaded: @rpath/SwiftSocket.framework/Versions/A/SwiftSocket
  Referenced from: /Users/jonathan/Library/Developer/Xcode/DerivedData/socket-buglawjxihebcabvcihcbdrtkcxt/Build/Products/Debug/socket
  Reason: image not found
(lldb) 

EDIT2: Something was funky with my Xcode. I've reinstalled it and now it seems to work fine. Thanks to everybody for the help. :)

Jonathan
  • 99
  • 1
  • 8

4 Answers4

4

I would like to comment, but I don't have enough reputation. Anyway did you write something like:

import SwiftSocket

in the class where you need it? Also, did you open the project with the xcworkspace extension? If nothing works try to clean and rebuild the project

JamesRGNT
  • 586
  • 1
  • 6
  • 17
  • 1
    I've tried that as well, as well as creating a new project and trying to import this, no success – Jonathan May 11 '17 at 07:10
  • Try to add it in 'Linked frameworks and Libraries' into 'General' of your project's targets – JamesRGNT May 11 '17 at 07:32
  • Is the library present in 'Link Binary With Libraries' into 'Build Phases'? – JamesRGNT May 11 '17 at 08:52
  • I personally don't have any other clue, try to look at [this](http://stackoverflow.com/questions/24333981/ios-app-with-framework-crashed-on-device-dyld-library-not-loaded-xcode-6-beta) and [this](http://stackoverflow.com/questions/22265408/cocoalibspotify-library-not-loaded) – JamesRGNT May 11 '17 at 10:04
  • reinstalling xcode solved the problem. import SwiftSocket is enough and works. thanks! :) – Jonathan May 11 '17 at 10:18
2

Based on my checking of the SwiftSocket Library, it seems that what you did should be fine (it should be pod 'SwiftSocket' referring to "Installation" section), I assume that you missed to add :

import SwiftSocket

in your main.swift class.

And yes, they are not mentioning that in "Code examples" section because they -probably- assume that importing it in your .swift file should be obvious.

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
2

Once CocoaPods is finished installing, you need to start using the .xcworkspace instead of your .xcproject file. So close your project, open the workspace (same directory), and import SwiftSocket.

Oskar
  • 3,625
  • 2
  • 29
  • 37
1

Your Podfile seems correct, after that, you need to launch a terminal from your project directory:

cd ~/Desktop/MyProject/

Then run: pod install command.

This will create a .xcworkspace file and a Pods directory. Now you have to open the .xcworkspace file with Xcode.

Donc forget to import yout pod like this: import SwiftSocket

Also take a look at the CocoaPods documentation: https://guides.cocoapods.org/using/using-cocoapods.html

Jimmy James
  • 825
  • 12
  • 28