How to use any framework without CocoaPod in Xcode - ios

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

Related

"FileName.h" not found in Xcode 8.2 , Objective-c

I am preparing a SDK in objective framework, i added a file and imported a "FileName.h" but it giving me an error of file not found.
Any suggestion will be greatful
Are you able import the framework in your project. If YES, check
Framework Search Paths in Build settings.
Example: $(PROJECT_DIR)/xxxxxxxx/GoogleSignIn\
Add your framework inside
Embedded Binaries

Create swift framework without exposing the implementation

I have created a framework in swift where I have made limited number of classes as public.The default header which will be present on creating any a framework has only version number info. But when I try to use the framework, I am not able to access even the public classes and methods.
Can anybody suggest how could we create a swift framework without exposing the implementation.
It's how you pull a Swift Framework target into your app project that matters, not the header file. And if you are using Swift 3, you'll want to designate your classes as open, not public.
Option #1: Add the Framework's .xcodeproj file to your app's project.
You'll be able to edit the framework's source this way, but only only project can have it open at a time.
Option #2: Import the Framework's .framework file to your app's project.
You'll need to add this into your app's Linked Frameworks and Libraries. Also, you'll need to remember to reload it every time you make changes to the framework.

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)

How to install CocoaAsyncSocket library into Swift?

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"

How to use third party lib in embedded dynamic framework for iOS with swift

Now I have a project, like testApp, using some third party lib like alamofire and some others libs in objective-c.
Now I want to add a today widget. According to some tutorial, I created a new target "testAppKit" as a shared dynamic framework, and target "testAppWidget" as today extension. The common code will be in testAppKit for reuse.
Now I need to use third party libs in testAppKit. And added lib and header in build phases of testAppKit. Then I add #import <theLib/TheHeader.h> in testAppKit.h. But there is an error:
Include of non-modular header inside framework module 'testAppKit'
So, I want to know how to use third party libs (maybe in Swift or Objective-C) in this kind of embedded dynamic framework.
I use Dropbox Datastore API in my app and I finally made it working for embedded Cocoa Touch framework to share code for Containing App and Today Extension.
I figured out that in my Swift file in the embedded framework I can import any 3rd party framework I had in the Project (i.e. Farbic.framework, Crashlytics etc.) but not Dropbox.
What was the difference? The "Modules" folder! Dropbox.framework doesn't provide module map file. So I created it based on what I found in Fabric.framework:
Go to the Dropbox.framework folder in your project direcotry.
Create new folder "Modules" and go inside
Create a file called: "module.modulemap"
The content of the file:
framework module Dropbox {
umbrella header "Dropbox.h"
export *
module * { export * }
}
After doing that I needed to add import path.
Go to your Project file
Select your embedded framework target
Go to the "Build Settings" and find "Swift Compiler - Search Paths"
Add path to your Dropbox.framerowk and set "recursive" option.
I wanted to put a screenshot here but I can't do that yet - because of my "reputation" ;)
Now I'm able to do "import Dropbox" in my swift files :)
Hope this can help you :)

Resources