Import class from development pods with CocoaPods - ios

I get a little older project from another developer and I should fix some issues and add new features. The project is mainly written in ObjC and is using CocoaPods as dependency manager. Previous developer create his own pod in Development Pods and it contains mainly business logic for application. So I needed add some classes there like RCZMortgage. But when I try to use it in main project I get problem:
'RCZMortgage.h' file not found
So I was thinking that I must update pod. So I use command update pod for that one development pod but after that I started have problem with Bridging-Header.h and that files in there can't be found (I don't know if update fix previous problem or just bring more). Previous developer start creating a few classes in swift.
Bridging-Header.h looks like this:
#import "RCZAdvertisementBadge.h"
#import "UIView+Centering.h"
#import "UIColor+CustomColors.h"
#import "UIView+Sizing.h"
#import "SDWebImageManager+AutoScale.h"
#import <SDWebImageManager.h>
#import "RCZImageUrlBuilder.h"
In podfile there is:
platform :ios, '7.0'
but there isn't use_frameworks!
I'm not sure which informations you need to help me. What files should I write here to help me. So any comments and answers are welcome. I can't contact previous developer so I am asking here.

Check weather pod dependencies are correctly matched in build settings.
Give correct pod path, clean the code and try once more.

you should check this tutorial for pod file How to Use CocoaPods
Hope this will help you.

Related

Objective-C class can't import swift pod defined at top level

Here's my Podfile:
platform :ios, '9.0'
use_frameworks!
target :Test_Swift_Import do
pod 'BFKit-Swift', '1.5.1' //Just a swift pod to provide some methods to test
pod 'SwiftySwift', '1.0.1' //and another
end
In my AppDelegate class I try to use a simple method from BFKit
BOOL isEmail = [#"not an email" isEmail];
My AppDelegate is an objective-c class, not Swift
In order to make this work I try to import the BFKit Swift module
First I try the well-known way:
//Basic <Product_Name-Swift.h>
#import <Test_Swift_Import-Swift.h>
But this SO post and this one too both say to use <ProjectName/ModuleName-Swift.h>. Because the code is in a module, this makes sense to me.
So I try #import <Test_Swift_Import/BFKit-Swift.h>
No deal...
I rename my project to TestSwiftImport in case underscores are a problem
No deal...
I try importing the module directly
<BFKit/BFKit.h>
Alas...
Relevant Xcode Build Settings
defines modules : Yes
Product Module name: TestSwiftImport
Enable Modules: Yes
Link Frameworks Automatically: Yes
Objective-C Generated Interface Header Name: TestSwiftImport-Swift.h
Objective-C Bridging Header: TestSwiftImport/TestSwiftImport-Bridging-Header.h
Drastic Things I've Tried
I've done all manner of cleaning project and build folder, wiping derived data, resetting simulator, quitting simulator, quitting Xcode and restarting machine, all to no avail. It's sad that these are even things I think of doing and that they sometimes work... But not in this case.
Github Demo Project Displaying Problem
...is here
Any ideas? There are even more failed attempts that you can see if you open the project. This can't be this hard...
I see that is problem of CocoaPods.
Now If I try drag file straight to xcode it will work normal. If you really need it. You can drag all file to project. Not use cocoa-pods now.
You can reference to this question: Question
Hope this help!

Swift 'Could not build Obj-C module 'BranchInvite'

I've been following the instructions for implementing this SDK: https://github.com/BranchMetrics/Branch-iOS-Invite-SDK... below is what I have in my Podfile:
platform :ios, '8.0'
use_frameworks!
target 'My-App' do
pod 'BranchInvite'
end
And here is the error I'm getting...
I've done a lot of troubleshooting to try and figure out the problem, looked at past issues of this reporsitory of this sort, and for some reason I cannot get "BranchWelcomeViewController" (nor BranchInvite) to be recognized/imported. Any idea what I'm doing wrong here? Do I need to populate my bridging-header?
PS: I'm using Xcode 7, Swift 2, OS X 10.10.5, and the latest version of Cocoapods.
Thanks
#SamYoungNY, after debugging using the project you sent over, the best approach using Swift appears to be the following:
Podfile
pod "Branch"
pod "BranchInvite"
your app's bridging header
#import <Branch/Branch.h>
#import <BranchInvite/BranchInvite.h>
#import <BranchInvite/BranchInviteViewController.h>
#import <BranchInvite/BranchInviteTextContactProvider.h>
#import <BranchInvite/BranchInviteEmailContactProvider.h>
#import <BranchInvite/BranchWelcomeView.h>
#import <BranchInvite/BranchWelcomeViewController.h>
#import <BranchInvite/BranchWelcomeControllerDelegate.h>
#import <BranchInvite/BranchWelcomeDefaultView.h>
Then be sure to use your project's .xcworkspace file if you weren't previously. Please let us know if this doesn't work. I'm happy to continue to debug with the actual project you sent over.
I received a lot of help from #st.derrick on this question, and there was something wonky with my version control but in the end I got it working with something I found in the branch.io documentation, the answer is in this link:
https://support.branch.io/support/discussions/topics/6000008855
I can't comment yet but here's the archived text from that thread SamYoungNY linked to.
If you're running into an issue where you know that you've imported >Branch, but Xcode can't seem to find it, we may know the answer. You're >probably seeing a screenshot like the one below:
(Picture not archived)
This likely means that you are importing Branch as a "folder reference" >and not a "group".
Delete the Branch folder from your project
Make sure Branch is no longer in your project's folder (in the file >system, not Xcode)
Re-import Branch and be sure to select "Create Groups" (see screenshot >below)

How to install SDWebImage

I need to manage photos in my app and have read much about SDWebImage framework which seems to be the best way to go.
However I am finding it incredibly difficult to install. I dont know Ruby and have never used a podfile, so am installing it by downloading the latest SDWebImagefolder & framework and adding them to my project. However when I try to import into my viewcontroller using the suggested imports:
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIImageView+WebCache.h"
I get a file not found with on the #import then if I change this to "SDWebImage/UIImageView+WebCache.h" as suggested I get a file not found on the: #import UIImageView+WebCache.h even though I can clearly see it when I open the SDWebImage folder in my project! I'm guessing that these errors also lead to a not found error when I try to use the sd_setImageWithUrl method.
Here's a screen shot of my project:
I hope I can get some help with this as the framework looks to have very good functionality. Any help very much appreciated. Thanks
When you add the SDWebImage folder in your project then select following option. To add copy of your folder to the destination project and Create groups.
and then you have to write just like
#import "UIImageView+WebCache.h"
And make sure that you are adding to all the targets that you want to use that library.
Documentation at Github :
Add the SDWebImage project to your project
Download and unzip the last version of the framework from the download page
Right-click on the project navigator and select "Add Files to "Your Project":
In the dialog, select SDWebImage.framework:
Check the "Copy items into destination group's folder (if needed)" checkbox
Or you can use cocoa pods as other answer suggested.
EDIT : EXAMPLE :
[self.imageView sd_setImageWithURL:[NSURL URLWithString:"yoururl.png"] placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
You can use CocoaPods to manage libraries in your project.
To add SDWebImage to your project you should add this line to your pod file:
pod 'SDWebImage', '~>3.7'
UPD
To use CocoaPods, you should install it, to create it you can open Terminal and copy/paste this line:
sudo gem install cocoapods
On next step you should create Podfile in directory that contain your project file. Pods it is text file (you can create it by using xCode or other text editor (only do not use Writer, it uses not correct character for " ' ")).
After you've created Podfile, you should run in Terminal next line:
pod update
It command'll create a workspace file, this file you'll use to open your project.
All instructions present on the home page of CocoaPods.
I ran into this issue recently, and a less intrusive way to fix this problem is to add an entry to your Header Search Paths (all 3 instances) with the content ./SDWebImage/ (assuming that's where the framework is) so that it considers that folder when looking for includes.
I think you have to use a Cocoa Pod file for SDWebImage Library.
init the pod file.
install Pod file.
and then update that pod file.
platform :ios, '7.0'
source 'https://github.com/CocoaPods/Specs.git'
pod 'SDWebImage','3.7.1'
pod 'UIActivityIndicator-for-SDWebImage'
And then you can import the following file.
#import "UIImageView+UIActivityIndicatorForSDWebImage.h"

Google/Analytics.h file not found when adding to AppDelegate

I am trying to integrate Google Analytics in my ios project using Cocoapods. However, after following this for the steps till adding configuration file to my project, when importing the Google/Analytics.h in AppDelegate I get error for file not found. Tried following things:
Added $(SRCROOT)/Pods/GoogleAnalytics to User Header Search Paths in Build Settings.
Added libGoogleAnalyticsServices.a to link binary with libraries in build phases.
Added -lGoogleAnalyticsServices in Other Linker Flags.
Don't really want to do 2 and 3 as they make it free from Cocoapods.
What exactly am I missing?
Swift 3
With version 3.17.0 (installed using pod 'GoogleAnalytics' in Podfile):
Open yourproject.xcworkspace instead of yourproject.xcodeproj
Use #import <GoogleAnalytics/GAI.h> in the bridging header file
Edit:
Per jeremy piednoel's comment you may also need
#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>
Problems
The code examples on the official documentation suggest
installing 1.0.0. Which doesn't even have binaries compiled for
arm64.
There seem to be at least three separate pods related to
GA. GoogleAnalytics-iOS-SDK, GoogleAnalytics, Google/Analytics.
Solution
Add this to your Podfile: pod 'Google/Analytics' and then pod install.
That should work. Now you can simply import Google/Analytics.h as suggested in the docs:
#import <Google/Analytics.h>
Further Discussion
There were two sets of issues that I ran into:
When using the incorrect suggested pod version (1.0.0), was a 64-bit compatibility issue. (ld: symbol(s) not found for architecture arm64)
When using the other pods (GoogleAnalytics-iOS-SDK and GoogleAnalytics) I had complaints of a missing <Google/Analytics.h> header file. ("Google/Analytics.h" not found)
I found this gentleman's post on a mailing list which suggested the Google/Analytics pod with no version number. (pod 'Google/Analytics' as noted above.)
This is a bug in cocoapods.
you need to add $(SRCROOT)/Pods/Google and $(SRCROOT)/Pods/GoogleAnalytics with recursive option to your User Header Search Paths.
Then include the #import "Analytics.h" instead of #import
When you add $(SRCROOT)/Pods/GoogleAnalytics to User Header Search Paths in Build Settings, also select recursive option. It will allow your project to search in GoogleAnalytics and all of its sub-directories.
UPDATED:
I have tried the tutorial and it works fine without any extra step. My pod version is 0.35.0. When you create configuration file, remember to enable GoogleAnalytics service.
UPDATED:
As #RajatTalwar pointed out, you also need to add $(SRCROOT)/Pods/Google with recursive option. Then include the #import "Analytics.h" instead of #import
If anyone else out there is having an error with trying to #import <Google/Analytics.h>, and the other solutions online aren't helping you, you should read on.
I was having this problem and none of the solutions I found would fix it. Then I noticed that one of my targets worked while the other one did not (I had two in the same project), and I tried to track down what was the difference between the two targets.
I noticed that there was a difference in the project on the General tab under Deployment info, where the second target (the one which worked) had separate options for iPhone and iPad, but the first did not. Someone else online said that they received these two new options when they duplicated their target. My second target was also a duplicate of the first, originally.
To make a long story short, I found that if I duplicated my target that the duplicate now suddenly worked. Those separate iPhone and iPad options also magically appeared. So I guess my project target was non-standard and causing a problem, probably because this project was created a long time ago.
I then just deleted the original target and renamed the new one to be the same name, although there was some cleanup work required in the build settings related to the plist file (it made a copy.plist file).
Hope this helps someone.
Check if you have multiple targets, in this case add pod 'Google/Analytics' foreach target in you pod file:
def google_pods
pod 'Google/Analytics'
end
target 'target 1' do
google_pods
end
target 'target 2' do
google_pods
end
target 'target N' do
google_pods
end
Also my $0.02 to this, since it seems to be a never ending story. None of the suggestions above did help. I got this obscure message from pod install
[!] The `blabla [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-blabla/Pods-blabla.release.xcconfig'. This can lead to problems with the CocoaPods installation
Finally I inspected my project.pxbprojand found, that I had this entry:
HEADER_SEARCH_PATHS = "";`
Obviously this is treated as "defined", so I changed it to
HEADER_SEARCH_PATHS = "$(inherited)";
and boom - all the Google suggested includes work
#import <GoogleAnalytics/GAI.h>
#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>
Run pod update
Clean Build Files
Run Project
remove valid archs from build settings

Xcode can't see objects added via Cocoapods

I have a podfile defined with the following pods.
platform :ios, '8.0'
use_frameworks!
target 'LifeStream' do
pod 'SSKeychain'
pod 'LiveSDK'
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift-2.0'
end
I installed the pods and opened up my workspace. I have found that any usage of Alamofire works fine, due to the Swift 2 version of it importing the project as a framework.
When I try to use SSKeychain classes however, I receive a
Use of unresolved identifier 'SSKeychain`
Same applies with any class I try to use in the LiveSDK.
I have a bridge header in my projects root directory, and the project is configured to use it.
#ifndef Header_h
#define Header_h
#import "SSKeychain/SSKeychain.h"
#import "LiveSDK/LiveConnectClient.h"
#endif /* Header_h */
if I change the #import from
#import "SSKeychain/SSKeychain.h"
to
#import "SSKeychain.h"
Xcode fails to compile because it can't find the file. So I assume that the bridge header is working, as the way my bridge header is built now does not generate any compiler errors caused by not finding the headers.
Bridge Header
Framework Search Paths
I have also added my project root directory to the framework search path.
Linked Frameworks
Lastly I have linked all of the frameworks to the project as well.
Am I missing something with my setup? I have not been able to get Cocoapods to work on my project for nearly a week now. I even created a brand new project thinking that mine was just messed up; which didn't change a thing. I don't know what to do from here in order to resolve this.
Edit
After doing some additional research, I found a blog post showing that you have to include your Pods directory in the User Header Search
A commenter also mentioned that if you are using the newer Cocoapods Frameworks support for Swift, then it will need to include the Frameworks/** search path. I've included both Pods/** and Frameworks/** but still have the same issue.
After some further reading, it's beginning to sound like this is a limitation of Cocoapods. From what I understand, you can't use libraries and frameworks together at the same time in a project.
Once you use use_frameworks! in your Podfile, Objective-C Pods like SSKeychain also get build as frameworks.
The actual problem is that only module imports work in the bridging header when using frameworks. Also, you might want to get rid of the bridging header entirely, as it is unnecessary when using frameworks, they can be imported directly in Swift.
To clarify what you should do to make it work:
Be sure to have use_frameworks! in your Podfile
It doesn't matter if you have a Bridging header or not. Leave it untouched
In your SWIFT file just use import Podname
That's it, you're good to go. Of course it may happen that you need to clean your project or maybe delete the derived data folder. Build and you can use it.
If you're not using any swift pods,
Try removing the use_frameworks! on your Podfile.
Run pod install on terminal.
Clean & Build !
I spent almost half an hour fixing it, I tried adding those paths on Search Paths or re-adding the bridging-header but the error was the same.
Therefore, in my case, bridging header file was not the problem, its on the Podfile .
I hope it helps!

Resources