Jonathan
Jonathan

Reputation: 99

Using installed pod in swift project

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

Upvotes: 2

Views: 902

Answers (4)

Jimmy James
Jimmy James

Reputation: 847

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

Upvotes: 1

Oskar
Oskar

Reputation: 3702

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.

Upvotes: 2

Ahmad F
Ahmad F

Reputation: 31645

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.

Upvotes: 2

JamesRGNT
JamesRGNT

Reputation: 616

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

Upvotes: 4

Related Questions