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. :)
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
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.
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.
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
Related
I have the same problem as described here: I cant add socket.io module to my project.
I've tried all ways of dragging and dropping as described in answer, I've tried adding files to project from File menu. No matter what I do I get compile error "SocketIO module not found" on string import SocketIO
Is there a regular way of adding modules? Command line? Sorry if question sounds dummy - Im new not only to swift but to mac also (bought it to learn swift).
If that´s an issue (which it seems to be for not only you) I would go with CocoaPods instead.
Start by:
Do this in your terminal: sudo gem install cocoapods
Go to your project folder and open the terminal in that folder (cd ...)
Do this in your terminal: pod init
Remove all content in your newly created pod file and add this instead:
use_frameworks!
target 'YourApp' do
pod 'Socket.IO-Client-Swift', '~> 12.0.0' # Or latest version
end
Do this in your terminal: pod install
Open your project, note that you need to open the .xcworkspace file to be able to access your pods
Import the module import SocketIO
I created a sample project for you with CocoaPods installed and I have added SocketIO for you. Remember to run the .xcworkspace file. You can download the project here.
Add the socketio swift client with CocoaPods , but after that set the source of the client to Swift 3.2 then try to build it. I’m assuming you’re using Xcode 9 . To set the source to swift 3 from Xcode : go to Frameworks, select the SocketIO and go build settings and set Swift version to Swift 3.2
I faced this problem and it killed my 4 hours time.
I did the steps given by #Rashwan L but it didn't solve my problem though.
I was set iOS Deployment Target to 10.0 that was my main problem.
When I changed my iOS Deployment Target to 11.1 it works for me.
Good luck.
I'm trying to use the firebase pod, however getting this (see image) error message when a run is attempted.
I followed this guide to install Cocoapods and added the firebase dependency to the Podfile.
p.s I tried to clean it a bunch of times.
I got stuck for awhile trying to solve this, but the solution turned out to be very easy :)
If you are using Cocoapods in your project, one needs to use xcworkspace to build instead of xcproject.
If you are using Cocoapods and build from xcproject , it will ignore the Cocoapods libraries you need.
Sometimes its because of you might be declaring an object with same variable name.
Clear the repeating variable name change it. After that clean your project and build again.
Its worked for me....! Thanks.
I faced the same problem for hours and solved it with a simple hack. Just do clean and then Build
This error will also trigger when several components (files) with identical names were added to Xcode workspace.
Renaming them will fix this error.
A bit late, but what did the trick for me were cmd + q xcode, navigate to project folder, pod update, reopen open the .xcworkspace file, clean project and run/build again.
Sometimes occurs when you perform an invalid delete through cocoapods.
In my case I installed a framework through cocoapods which required bitcode set to "enabled", later when I longer needed it removed it from Podfile and pod install.
That's when encountered this error, solving it by setting the required targets to "disabled" in bitcode option.
I've got the same error when I was trying to configure cellIdentifiers in different Controllers.
I declared two variables globally with the same name. To solve this error I just renamed the second variable.
#import "ResultsTableViewController.h"
NSString *const kNormalCellidentifierName = #"NormalStoryCelll";
#interface ResultsTableViewController ()
#end
For me it was because the pod that I was using used Swift and I didn't include the use_frameworks! line in my podfile.
I didn't include that line before and therefore had to create a Swift file in my project and a Objective-C bridging header (which Apple offers to do for you the first time you add a swift file to your project).
If you told it not to create the bridge, then you can use this guys tutorial to manually create it as well as the settings needed.
I have tried a lot to fix this issue and failed for every attempt.
Then i just simply used:
pod install
and to my surprise, simply it solved my issue.
The idea is to have an api framework (new project -> cocoa touch framework) for example "SuperApi". SuperApi use pods like Alamofire, ObjectMapper and whatever I need.
Next I want to integrate that SuperApi into my app like a normal framework.
I tried different ways. I tried to add it at "Embedded Binaries" and/or tried to add superApi at "Linked Frameworks and Libraries". Without success. I always linked the whole framework-folder.
import SuperApi threw always an error: could not find framework
Then I read something about workspaces where I can have a lot of projects parallel. This seems really overpowered for an api.
Create a framework without pods (xcodeproj) is no problem. There are a lot of descriptions in web. But what is a (good) solution for my problem?
I don't want to write my own http-networking + JSON parser. Thanks for input.
Why don't you add your SuperApi as a pod of your main project? You can have it either as a local pod, directly linking the last commit or using your own private repo
There's a very nice tutorial by Ray Wenderlich: https://www.raywenderlich.com/99386/create-cocoapod-swift
Thanks Eli. I found this video, it's more up to date
https://www.youtube.com/watch?v=gNMNeqXKnzw&t=964s (thanks to you Mr. Levi Bostian - you made my day)
Unfortunately this video is a litte bit outdated too.
You run into a Swift 2/3 issue. So you have to create a .swift-version in your git. For example Alamofire did it like this: https://github.com/Alamofire/Alamofire/blob/master/.swift-version
You can do it like this in your pod-folder: echo 3.0 > .swift-version
I ran into a second issue, because my pod wasn't up to date. So update your pod sudo gem install cocoapods --pre
Last but not least I had a warning in my podspec, so I have to use pod spec lint --allow warnings
Better way is to fix the warning ;)
Update: I solved the question. Please see my answer below (underneath the question and comments).
This question was marked as a duplicate, but it's different because it is a brand new error that I couldn't find through any searches.
I tried installing Alamofire into my XCode project.
As per their their tutorial, I installed cocoapods onto my system.
I then navigated to the folder of my existing xcode project in the terminal, and did:
pod init
I then edited the new pod file and added:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target 'RainyShinyCloudy' do
pod 'Alamofire', '~> 4.4'
end
Finally, I executed the command:
pod install
My terminal told me the install was successful.
But when I opened the .xcworkspace, made a new swift class and tried to import Alamofire, I got this error:
One possible reason could be that I had tried to install an earlier version of alamofire earlier, deleted it and then installed this.
But I really don't know how that could have mattered.
Thanks for any help you guys can give me.
Actually it failed because you were trying to import AlamoFire and not Alamofire. Imports are case sensitive.
Update: I posted an answer earlier that was wrong.
But now I actually figured it out.
I made a new project, went to the settings menu by clicking on the name of my app in the project explorer.
Then I went to Linked frameworks and libraries which is at the very bottom of the General tab.
I pressed that little + icon, selected Alamofire.framework. and set the status to required
Following this, cleaning and rebuilding the project made the error go away.
I've tried everything. EVERYTHING. I have no. idea. what Im doing wrong here.
Ive downloaded test projects and followed every step under manual installation AND install using pods here: https://github.com/PureLayout/PureLayout#problems-suggestions-pull-requests
I already have Parse and some other modules installed via pods so I first went to pods. I first went to my pods file and wrote
use_frameworks!
pod 'PureLayout'
JUST as the working sample projects did. I then navigated to my project (I think I did this right - went to terminal did cd Desktop then cd my project name, didn't think I had to cd anywhere else) and ran pod install . After this nothing happened in terminal (I got no response no matter what I did) and no PureLayout files were added to my project.
I still got no such module Purelayout when trying to trying to import PureLayout so then I tried manual.
I have dragged the files here https://github.com/PureLayout/PureLayout/tree/master/PureLayout/PureLayout into my project and imported in my bridging header:
Tell me if Im missing something. I still get no such module - even checked in my build settings that it had the right bridging header. I can continue without this and have no ideas - What am i doing wrong?
Is this an impossible problem?