How to install CocoaAsyncSocket library into Swift? - ios

There are a lot of information on how to use GCDAsyncSockets with Objective-C but so few with Swift, and almost no information on how to actually install it into the Xcode environment. I tried adding files in the zip file one at a time with File | Add Files to ... Project menu option but still I cannot use the added files with "import GCDAsyncUdpSocket" statement. It says "No such module". There's gotta be an easier way of doing this, right?

Install using CocoaPods by adding this line to your Podfile:
use_frameworks! # Add this if you are targeting iOS 8+ or using Swift
pod 'CocoaAsyncSocket'
CocoaAsyncSocket is Carthage compatible. To include it add the following line to your Cartfile
Carthage/Build/iOS/CocoaAsyncSocket.framework
Carthage/Build/tvOS/CocoaAsyncSocket.framework
Carthage/Build/Mac/CocoaAsyncSocket.framework
Select the correct framework(s) and drag it into your project.
Manual
You can also include it into your project by adding the source files directly, but you should probably be using a dependency manager to keep up to date.
Importing
Using Objective-C:
#import CocoaAsyncSocket; When using iOS 8+ frameworks
or
#import "CocoaAsyncSocket.h" When not using frameworks, targeting iOS 7 or below
Using Swift:
import CocoaAsyncSocket

I following this steps successful use the AsyncSocket class by CocoaAsyncSocket
copy CocoaAsyncSocket project source on github
click CocoaAsyncSocket.xcodeproj file open CocoaAsyncSocket project
copy iOS version AsyncSocket.m AsyncSocket.h AsyncUdpSocket.m AsyncUdpSocket.h file to your use CocoaAsyncSocket project
xcode will tell you create a Bridging-head file,create it
edit the xxx-Bridging-head.h(xxx is your project name)file add #import "AsyncSocket.h"

Related

Mixed language framework with Cocoapods

I'm creating Swift framework that will be distributed via Cocoapods. Inside MyFramework I use few frameworks installed via Cocoapods. Importing frameworks written in swift works fine, but I get trouble importing objc framework. I want to use CardIO inside MyFramework and add it as pods submodule, so user can optionally install it like pod 'MyFramework/CardIO'. After installing CardIO pod in MyFramework, I try to import it in MyFramework-umbrella-header like:
#import "CardIO/CardIO.h"
but get the error:
"Include of non-modular header inside framework module ".
I also check this answer, but this doesn’t work when importing objc framework. Any idea is it possible to import objc framework that installed via Cocoapods to Swift framework?
[FIXED]: The problem was in CardIO podspec, they import only .h files as source_files. So after including .m files to source files: .source_files = 'CardIO/*.{h,m}' Cocoapods generate CardIO modulemap, then it's possible to import CardIO module in Swift framework.

How to use any framework without CocoaPod in Xcode

I am developing an iOS application using Swift language. I want to use some framework in this application. There are some frameworks which can be installed using CocoaPods, so is there any way to use those frameworks without Cocoapods? Can I add them directly to my project?
Thanks..!
Yes you can. go to source file and check there will be .h and .m file for objective c.drag that file into your project and import it into header class and as per need you can use it

Using Swift library in an Objective-C project

I am working in an Objective-C, iOS project, I used danielgindi Charts library which is a Swift library. I downloaded it using Cocoapods.
I am trying to import the library files into my Objective-C files using 'projectName-Swift.h' as mentioned in this question but I faced an error:
'projectName-Swift.h' file not found
If you have installed Swift library using cocoapods
To import Library in Objective C Code
Use
in Objective C
#import frameworkname;
In Swift
#import frameworkname
If your using cocoa pods try to make sure you have use_frameworks! in your cocoa pods pod file, otherwise the Swift Framework wont work. Also look at this for any other issues that may pop up: link
For making the bridging header visible to your compiler you need a little setup
Go to your Project Build Settings
Search for bridging header
Add the path to your
.h file (usually ProjectName/ProjectName-Swift.h)

Issues adding libraries to xCode Project manually

I have been trying to add SwiftyJSON and SWXMLHash to my Swift project, however when I add them the files have many (40+) compile errors?
I have read the instructions on there git projects carefully and both projects say I can just drag the .swift file to my project, and this is what I have been doing.
I can't use CocoaPods or Cartage as I am targeting iOS 7

How can i use the libraries after importing dependencies using cocoapods?

I am facing issues in actually using the libraries contained within the dependancies. I followed the procedure up to the letter but yet xcode gives me errors when i try to import the kit i need to use. Heres what i have done:
create pod file at the project directory
install the pod file with dependancies
open .xcworkspace file created
create a bridging header in objective c
enter path of the bridging header to the build settings
After doing all of this, when i write the import statement (eg. import IMFData) xcode shows that it doesnt exist/ cant be found.
Could somebody shed some light on the what i am missing?
Try adding use_frameworks! to your pod file and then run pod install again. You won't need to use a bridging header then and will be able todo import IMFData alternatively if you aren't using Frameworks when you use the bridging header you don't need to use the import IMFData just access the classes within your swift class.

Resources