Cant import module to xcode - swift

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.

Related

Xcode 12, iOS 14, Pods

After updating the iPhone to ios 14, xcode 11.5 stopped launching projects on the iPhone, I decided to upgrade xcode to version 12 and got a huge number of errors related to Pods for 60 of them ... Basically, everything is related to the fact that quotes cannot be used in Pods, and need to use <> to connect libraries. When I correct it with <>, I get errors that I need to use "", but this is all warning, namely error due to the fact that xCode stopped seeing one library. On the screen all the info.
Thank you in advance for your help)
How to fix it?
I had a similar issue and I fixed by changing the deployment target of all Pods. Most Pods were targeting iOS 8.0, which is no longer supported by Xcode 12.
Make Sure You have Same Version for your deployment target and podfile platform
Don't open your Project in XCode 12 after XCode Update
Open Your Project Podfile through terminal
Just remove all your lib and do pod install (Also remove that extra codein podfile if you have written anything regarding architecture of 86 or 64 which we have write for remove warnings)
Clear derive data by path without opening XCode (~/Library/Developer/Xcode/DerivedData)
After Removed all lib all other lib again and do pod install
Open Your Project and set Build System to New Build System (Default) in Shared Workspace Settings and Use Shared Setting in Build System in Pre-User WorkSpace Settings (You can found this settings while XCode Selected go to file menu and click on WorkSpace Settings)
Then Do Clean and build then run it you will not found things regarding module not found you will face some syntax updates or any lib updates fix those and go for run
Try to install pod again, remove all pod and install again.
pod deintegrate
pod install
or
sudo rm -fr ~/Library/Caches/CocoaPods/
pod install
clear DerivedData and run again.

Installing Package with CocoaPods

I'm trying to install the Charts package to use with CocoaPods and it keeps saying "No such module 'Charts'".
If I added the pod 'Charts' in the podfile, and did a pod install and the files are there in Xcode, how come it still gives me an error when I try to import Charts?
Do I still need to do the steps below? Or does CocoaPods do it for me?
Drag the Charts.xcodeproj to your project
Go to your target's settings, hit the "+" under the "Embedded Binaries" section, and select the Charts.framework
My pods file looks like this now:
You just have to hit Command-b to build, then the error will go away. The other solution is to hit Product > Build.
I had a similar problem when I was developing an app for an older platform. The CocoaPod I sourced supported Swift 4 but I was developing for Swift 3. When I sourced the last Swift 3 version of the pod, the "No such module" error was no longer there. Try the following line in your Podfile:
pod 'Charts', '3.0.3'
instead of the latest version.
try installing it manually moving the complete charts folder to your project, or downloading using carthage, it's way more cleaner using carthage than cocoapods because it doesn't create you a .xcworkspace like cocoapods.

Cocoapods: Cannot load module 'Alamofire' as 'Alamofire'

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.

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

Cocoa pods GLM Error

So today I've been trying to try out a new project using Swift, but I've arrived to an abrupt halt. I've been trying to run the VideoCore sample project found here: https://github.com/jgh-/VideoCore/tree/823ec7cac50e5a0b4457bd06dd95a50dca88d9c0/sample/SampleBroadcaster-Swift.
So during the initial setup I had to navigate to the directory and run pod install. pod install executed without any errors, and say I need to close Xcode, and reopen the new workspace, which I did. When I try to go and run the app for debugging (as according to the documentation I can run it right after pod install'ing, I get an error that says 'type_half.inl' file not found. A few screenshots are here to better explain/show: http://d.pr/i/14TqW, and http://d.pr/i/1aYSi.
I've tried reinstalling the pod multiple times, and I haven't been able to resolve this issue. Has anyone had a situation like this, or have any idea on how to get out of this blackhole?
Thanks!
This has been resolved by downgrading CocoaPods to version 0.38.2. Here's what I did:
gem install cocoapods -v 0.38.2
gem uninstall cocoapods -v 0.39.0
And that fixed my issues.
Instead of downgrading CocoaPods to version 0.38.2. This error can be resolved in other way as I have fixed recently on of my project.
STEP 1:- Search Header Search Paths under build setting on GLM target or target that uses GLM pod like in my project VideoCore cocoapods uses GLM
STEP 2:- make it recursive instead of non-recursive.
Build again error will be fixed.
NOTE:- if you update cocoapods that you have to redo the steps again. Also target will be in pod project.
Attached image for reference.