Cocoapods import development pod into Swift - swift

I have a development pod which contains Objective C code. I would like to import this into my Swift project. Previously, I just added the header files to the Bridging Header file and everything worked fine. Now I'd like to use the use_frameworks! flag to build the development pod as a dynamic framework.
When I do this, there are errors in the Xcode project.
Use of unresolved identifier...
However, when I control click the class name in Xcode, it correctly takes me to the source file.
My question is - when I have a development pod that uses Objective C and I add this to a Swift project using the use_frameworks! flag, how do I import my files into the Swift code? Do I need to create some kind of bridging header file or use any kind of import statement?

Related

How to figure out the name to specify in import statement in Swift

Every time I import a Cocoapods library I have trouble in finding out what name to specify in the import statement.
First of all, should we always explicitly import the Cocoapods in all the files using the library?
If that's the case how can we find the name to specify in the import statement?
EDIT
Thanks for the answer about the necessity of import statement when using a library. I'm now completely clear about that.
About the package name, it seems like most of the Pods have a file with the extension ".modulemap" in their Support Files directory, and that is the one which specifies the module name. Is my understanding correct? It looks right but at the same time I have a doubt as well because some Pods(for example Fabric, GoogleSignIn etc.) don't have that.
should we always explicitly import the Cocoapods in all the files using the library?
Yes of course! If you don't import a module, you won't be able to use the types defined in the module.
how can we find the name to specify in the import statement?
Usually, this is the same as the name f the pod you write in your Podfile. The authors of most pods do this to avoid confusion. The names can be different though.
A good way of finding the module name of a pod is to go to the pods project in the left pane:
Click that and you will see all the modules listed out. For example:
Use the names you see in the list.
1. Every time I import a Cocoapods library I have trouble in finding out what name to specify in the import statement.
Sometimes it takes time to load pod installed in project as you had successfully installed a pod but when it comes to import name doesn't show
For this I usually do is command + b (Build project) just build project when you install a pod
or
Just Re-Open Project file after Successfully installing pods
2. Should we always explicitly import the Cocoapods in all the files using the library?
Yes, you need to import the pod in controller without this you won't be able to use its feature
3. how can we find the name to specify in the import statement
Usually the name is same as of pod File like alamofire
Pod AlamoFire and Import AlamoFire
if Still you find issues with name Check pod List installed In your project

How to create Cocoa GUI application with SwiftPM

I want to split my codebase into a library which I want to upload to github and an GUI application. I hope that using recently introduced SwiftPM is a good idea.
But all examples I've been able to find show creating a console application with swift package init --type executable.
I want to know how to create a skeleton for macOS Cocoa Application with all the pregenerated stuff like assets, storyboard and so on?
It would be great to have access to such useful thing as:
swift package build
swift package test
swift package update
...
Any ideas?
Thank you!
This is my working solution for creating cocoa apps with SPM.
Create your executable version of application: swift package init --type executable
Include your packages in Package.swift
Update/fetch them: swift package updateor swift package fetch
Create your .xcodeproj: swift package generate-xcodeproj
Open your .xcodeproj with Xcode; you'll see it as a console app.
Build your solution (this build will create dependencies: .frameworks, under 'Products')
Click the project name to see the targets
Add a new target by pressing + button below the list, and create your cocoa/gui app
After adding the app, click the app name on the targets list
Under General tab locate Embedded Binaries section.
Press + to add binaries, and select your referenced libraries.
Work on your cocoa app.
When you build, .frameworks will be embedded into .app
If you update your packages.swift, you should repeat above, except creating the new target; you'll just need to add it to the project.

Swift Framework with Chromecast: include of non-modular header inside framework module

I have found lots of suggestions on how to solve this error, but none have worked for me. I'm trying to build a framework that use the official Chromecast Framework. I get this error when I try to import Chromecast Framework:
I have created a very simple xCode project that recreates this error here.
How do I solve this (using xCode 7.1)?
This is a tricky one, the secret is to extract all the framework contents (headers files and static library) and include it on the project.
So, let's first extract the files and add to the project all this files:
Then make sure change all the references on your GoogleCast.h file (removing the imports using the framework "<>":
Now, select each header and put as a public header on Target Membership section:
And finally add the import on your .h file, remember put this import at the end of the file:
I create a sample project, you can downloaded here: https://dl.dropboxusercontent.com/u/31580788/TestChromecast.zip
If you are running a Swift project with Cocoapods, adding use_frameworks! inside your podfile will resolve this issue.
Don't forget to do a pod install after update though.
Cheers.

Xcode 7- CocoaPod AlamoFire & Others, imports into Project but is not working inside of project

I Am able to get the alamofire cocoapod imported into the project, but when I try to use the pod, Xcode does not seem to recognize that it is there.
Edit: I am working from the XCWorkspace
Are you opening the .xcworkspace instead of the xo.xcodeproj?
I'm not entirely sure of your problem, but if they're in your project but you can't use them in code, did you make sure to import them at the top of the file you're trying to use them in?

Use Cocoapods with an App Extension

I'm trying to build a photo App Extension in Xcode 6 Beta-6 that uses cocoapods libraries.
The bridging header that Xcode creates for the photo extension can't see anything from cocoapods.
For example: #import <GPUImage/GPUImage.h> results in the error "GPUImage/GPUImage.h" file not found.
I've tried every conceivable path for the import (with brackets and quotes) and have had almost no success. The exception is that for simple pods like SVProgressHUD, the following ugly terrible hack works:
#import "../Pods/SVProgressHUD/SVProgressHUD/SVProgressHUD.h".
But for GPUImage, it walks into the GPUImage.h header and decides it suddenly can't see GPUImageContext.h despite having no issue when this is imported with the bridging header for the normal swift code that is not part of the app extension.
What is different about the compilation of app extensions that is preventing the bridging header from behaving sanely?
Note:
I've read every possible permutation of this tutorial and it is not immediately applicable, just in case anyone thinks they have found the answer there.
Also, the problem described in this SO question may be related, but I asked this question anyway in case my issue is specific to app extensions.
EDIT (2015/03/10)
See new accepted answer. I tried it in a new project and it worked, although my test pods both used sharedApplication which is disallowed in extensions. The fact that they showed those errors means it linked properly. Way to go #LeChatNoir!
Success.
The solution is as follows:
Once you have your app extension and it's bridging header in a project using cocoapods and you want to use one of those cocoapods libraries, trying to include the pod like #import <GPUImage/GPUImage.h> will fail with file not found.
First, make sure that you tell the app extension (click on your project file, then on the extension target) to link against libPods.a, much like your app target.
Next, in your actual project (click on your project file, then on the project file again in the "Project" section of the inner sidebar) under the Info tab, set the configuration of the extension for Debug, Release, and Inhouse to use the "Pods" configuration from the dropdown. Pod Install will not do this for you, so you will need to do it yourself.
Lastly, make sure that both the Pods project's targets and your project's targets have all the architectures you need to build for in the Valid Architectures variable or you will get the ever-fun undefined symbols error.
This should work and allow you to import the pods of your choice like normal.
EDIT (2014/10/14): As an aside, since you may also be including Objective-C files from within your own project code in the Swift extension, you should make sure that any .m files you put in the bridging header are also compiled by the extension target. You can either do this from the compile sources menu for the target or in the .m file itself using the "Target Membership" section of the right sidebar in Xcode.
The above answers will work, but I only wanted a couple pods in my extension, so I did the following to my Podfile:
target '[Main App Target Name]' do
pod ...
pod ...
pod ...
end
target '[Extension Target Name]' do
pod ...
end
And then a pod install will do it!
The proper way to do this is to update your podfile to add just 1 line :
link_with 'yourApp', 'yourAppExtension'
and a pod update should resolve the issue.
link_with, you will not use it anymore.
Invalid Podfile file: [!] The specification of link_with in the
Podfile is now unsupported, please use target blocks instead..
Below is the perfect answe, tested also.
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, ‘9.0’
use_frameworks!
inhibit_all_warnings!
target 'DemoTodayWidget' do
pod 'Reachability', '~> 3.2'
end
target 'My Widget' do
pod 'Reachability', '~> 3.2'
end