Private pod with static library in along with swift pod - ios

I'm working on pods development for an iOS dev team (on private repo). My low-level C/Obj-C core pod contains a static library with some headers and is used as dependency in other pods (pushed with --use-libraries).
Now that the iOS team wants to integrate Swift pods, they had to add the use_framework! option in the Podfile of their projects. Of course, they obtained the following error during pod install :
The 'XXX' target has transitive dependencies that include static
binaries
I spent half a day on the web looking for a way to make my pods compatible with the use_framework! option, in vain. This is very frustrating, as Google Services pods are proofs that it's possible to bypass this problem in a clean way (not with the verify_no_static_framework_transitive_dependencies trick) : the main pod and almost all its dependencies contain static libraries, and everything works perfectly along with Swift pods. Exemple with Google/SignIn which depends on Google/Core (vendored_libraries: Libraries/libGGLCore.a) and GoogleSignIn (vendored_libraries: Libraries/libSignIn.a).
Any idea of what I can do to make my pods compatible with the use_framework! option ?
Thank you all,
Cheers,
Tom

I think I found a hack for my problem. This is quite weird, but I'd say it's clean enough to use it in production ;)
I found it here. The idea is simply to include a source file (even an empty one) in your source_files list inside your podspec.
Basically, the source section of my podspec looks like this :
s.source_files = "myLib/Empty.m", "myLib/Headers/*.h"
s.vendored_libraries = "myLib/myLib.a"
The only modification I made is to add "myLib/Empty.m" in the source files (Empty.m is strictly empty). Without it, I systematically have the transitive dependencies error when I pod install. With it, pod install works fine. It worked for me with both Cocoapods 0.0.39 and 1.0.0.beta.4.
Well, looks like it's a not so dirty solution, but I'm not sure it'll work in every case. And it's no good news about the cleanliness of Cocoapods...
As I mentionned in comments earlier, Google seems to have found a cleaner solution. So if anybody have an idea of the real clean solution, please share !
Cheers,
Tom
PS : I think I'll name the file DirtyCocoapodHack.m instead of Empty.m, sure they'll love it in the dev team ;)

Related

Cocoapods and Google Analytics transitive dependencies

I'm trying to create a private pod which uses Google Analytics. I include GA trough CocoaPods with pod 'GoogleAnalytics' but it keeps on failing with the transitive dependencies error.
I know there are already a lot of questions regarding this subject, but none of the solutions offered worked out for me.
Looked at Google's analytics site, but that didn't work out. I've seen this closed GitHub issue and scanned this dicussion.
Briefly looked at this small paragraph, which also clearly passes down the transitive annoyance to GA. At the bottom of the paragraph they say:
This eliminates the transitive dependency from the App -> Segment-GoogleAnalytics -> GA to App -> GA.
And of course, checked SO as well.
A little background info:
I use Cocoapods version 1.0.0
My podfile has use_frameworks! (I need that because I use Swift)
I include the GA pod with pod GoogleAnalytics
I also tried it with Google/Analytics and Google/Analytics ~> 1.3
Also tried adding pod Google before the GA pod
and not that it matters, but:
My Xcode version is 7.3.1
Some solutions say that I need a Cocoapods version after 0.36, and that the use of use_frameworks! should fix it. But as far as I know, and see in the generated Pods project, the GA pod still has a static lib (libGoogleAnalytics.a) and no framework.
This discussion has a lot of opinions and solutions, but as I already said, none work for me. Moreover, at the bottom someone said that this is a Cocoapods issue rather then something Google should fix (something with Cocoapods not taking use_frameworks! into account). But I beg to differ, especially since all other pods give me a framework as they should.
I had the error before when using OpenSSL, but fixed that by adding a compiled OpenSSL framework manually to my pod.
So I'm at a loss now. As for how I can fix this...got no clue whatsoever.
Edit
For now I've sort of circumvented the problem by using Carthage with the framework generated here.

iOS Project Pods have conflicting folder name

So i'm using these two pods in my project:
pod 'Google/SignIn'
pod 'MSOutlook-SDK-iOS'
To my delight, they both have dependencies that use a Core.h file. I believe i am running into issues that cause a File Not Found for one of the pods because it is looking for a file in the wrong header!
I guess I can make the import explicit, aka changing:
core.h/NSArray+Utils.h
to
orc/core.h/NSArray+Utils.h
But I don't want to do that bc of two reasons:
These pods get updated from time to time, and might introduce new files/overwrite existing changes
There are about 350 files I need to do that to.
Any ideas on how to resolve this? Possibly some renaming or settings change?
Thanks!
This purported error has claimed to been fixed in Cocoapods v1.0 and above.
From github:
"This ought to be fixed in CocoaPods 1.0 if you use bracket imports."

Xcode 7.3 Syntax Highlighting and Code Completion issues with Swift

I am having an extremely frustrating issue with XCode 7.3 (however, this issue has persisted since I installed XCode 7.2) and Swift code, and I am hoping others have had this issue and know how to resolve it. Syntax highlighting and code completion work perfectly fine in Objective-C files, and also works fine when calling other Swift objects within Swift code. However, any Objective-C objects or methods mentioned in Swift code get no syntax highlighting, and XCode will not complete ANY Objective-C declared methods or properties. Everything compiles and runs just fine.
I should also add that I have also tried doing a completely clean install of XCode. I deleted all my derived data, deleted all XCode caches, and deleted my XCode preferences files (in addition to obviously deleting the XCode.app archive before re-installing).
It is making it extremely difficult to develop in Swift. I don't want to do this, but if I can't find a way to resolve this I'll be forced to go back to using Objective-C.
I have the same problem. But finally solved it.
I make two change, not sure which is the key point but you can try them all.
delete the module cache
Within the same folder as your project's Derived Data is a Module
Cache. When Code Completion stopped working, deleting this fixed it.
Close Xcode and delete the
~/Library/Developer/Xcode/DerivedData/ModuleCache directory.
change the Enable Modules value
Go to the Build Settings of your target, then search Enable
Modules
If it's Yes, change it to No, and you may get some build
error, just change it back to Yes.
After two steps above you should Clean(Shift+Command+K) your project.
For now you may fixed the problem.
So it seems the issue was with CocoaPods. I was using Cocoapods as a static library instead of as frameworks. Switching to frameworks (using use_frameworks! in my Podfile) and importing the libraries into Swift has resolved all my issues. I'm guessing all those third party library headers were just too much for XCode to process. Either way, the issue is now resolved. I hope this helps someone in the future.
This might not be necessary anymore but i still want to post this:
At the time of this post, the most recent version of cocoapods (1.0.0.beta.8) requires you to define pods for each Xcode target.
In my case I had a class compile for the project target and for a testing target. I added a pod only to the main target, because of laziness.
Now working in the code of class A I added the pod framework using import NAME and tried to use the classes of the framework. Xcode wouldn't highlight the particular code where I use the new classes, but compiling and running works fine. In the completion dialog the type of the variable was <<error type>>
The way to resolve this issue: in the Podfile add the newly added pod to all targets, the class A is member of.
Now Xcode finds the necessary frameworks for all targets and code highlighting works again.
EDIT 1:
A possible solution is defining a list of shared pods, like in my example:
platform :ios, '8.4'
use_frameworks!
inhibit_all_warnings!
def all_pods
pod 'MPMessagePack'
pod 'SwiftyDispatch'
pod 'BFKit'
pod 'Timepiece'
pod 'Alamofire'
pod 'AlamofireSwiftyJSON'
end
def testing_pods
pod 'Quick'
pod 'Nimble'
end
target 'App' do
all_pods
end
target 'AppLogicTests' do
all_pods
testing_pods
end
target 'AppUITests' do
pod 'RxTest'
all_pods
testing_pods
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end
This will add all pods to all targets and adding all testing pods to the targets. Next to these I added 'RxTest' to the AppUITests.
(Chosen pods are examples of my projects, no advertising intended :-) )
We had the same issue in a mixed ObjC/Swift project. Tried all the suggestions about deleting derived data etc, to no avail. Sometimes it helped, but not in a reproducible way and after some time it stopped working.
The post of Galvin in this post put me on the track of the Module related build settings. However it was another setting that solved the code completion/coloring in a reproducible way: setting DEFINES_MODULE (under Packaging) from YES to NO for our main project was the solution.
Notes:
I expected this to break the ObjC/Swift interoperability in our project, but that still works. It seems that setting is only to be used for framework targets. (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html)
This project setting has not been changed for months, but the code completion issues came up only recently, both for my colleague and me.
If none of the above worked for you and you're using Cocoapods, you can try switching to Carthage.
I tried every suggestion I could find on Google to no avail. But consistently Cocoapods seemed to be coming up as a reason with many hacks in attempt to fix it. I have been reading up on Carthage, and how it doesn't modify your project, force you to use a workspace, or potentially fill your build folder with header files (which confuses Xcode and can cause the syntax highlighting and autocomplete to break).
After making the switch I haven't run into any issues yet, and to be honest I prefer the teensy bit of overhead to have a clean solution. This post really drove it home for me.

Editing locked files from a CocoaPods framework

I have an Xcode workspace that uses CocoaPods to include several third-party frameworks. I would like to edit a line of source code within one of these dependencies. However, when I do so, Xcode warns me that the file is locked and that any changes I make may not be saved. So my question is: will my changes to the source code be discarded when I run a pod install/update? If not, is there any other scenario, possibly unrelated to CocoaPods, that would discard my changes? And finally, is there any good way that I can edit the source code without running into such problems?
Thanks in advance.
You can not make changes in Original Pod file. If you want to add some more features then you have to fork that particular repo.
Follow steps to do so :
Find library you want to use on Git.
Fork library.
Update Podfile which refer to your forked version.
Suppose I want to fork GPUImage Library. Then point your fork in Podfile as given.
pod 'GPUImage', :git => 'https://github.com/UserName/GPUImage.git'
Make your changes.
Commit/push your changes to your forked repo.
Submit a pull request to the original author of Library.
If pull request is accepted and the pod is updated, revert back your Podfile to use the public pod.
You can create Category (Objective C) or Extension (Swift) to extend or add some features to existing class.
You can do this simple. Just modify the pods src code. Switch to another brach and switch back. Xcode would rebuild pods with your modified code.
If you want go back, you should remove the pod in Podfile, execute pod install.Then add pod back, execute pod install.
This solution is just for debug.
For permament, you should take #technerd 's answer
In fact there is another way in which you can modify the library as per your custom needs and get future updates from the library, all while still maintaining it via cocoapods
I have written article/tutorial explaining the same.
https://medium.com/#mihirpmehta/how-to-modify-cocoapods-library-within-pods-647d2bf7e1cb

Is there a way to find out automatically if a third party library has been updated

Im using a couple of libraries I found on GitHub, and I was wondering is there a way to know when a third party library used in an app has been updated? For example, a bug fix.
Must we continuously visit the users repository to find out for our selfs, or does using a dependency manager like Cocoa Pods have this functionality?
Thanks in advance.
Cocoa pods allows you to manage third party library, one feature it has it is pod outdated which checks for new releases of library's and also check if a project has new commits
more info on cocoa pods, see link
example 1 (library with releases only):
say you have AFNetwoking in your project using cocoapods with the following syntax: pod "AFNetworking" if you wanted to just check for updates do pod outdated, or to update the library if there are releases you would do pod update
example 2(library with most recent commits):
there times were you want to get most recent commits regardless of if it stability. On cocoapods you can do pod 'AFNetworking', :git => 'https://github.com/AFNetworking/AFNetworking.git'. this gets the most recent commit on git
CocoaPods handles this. Just type pod install every once in a while. It will fetch all available updates for you... I've been using CocoaPods for a long time without problems... You can even create private pods or development pods if you need to.

Resources