"Swift is not supported for static libraries" when testing cocoapod - ios

Recently I started creating my pod in Swift. I used pod lib create command and declined offer to use Nimble/Quick as testing library because I hoped to use standard XCTest. However, when I try to run tests, build just fails with message Swift is not supported for static libraries.
I tried to reopen Xcode and clean project, not working.
What should I do in this situation?

Swift don't supported static libraries. If you create lib used objc so you have 2 ways (create static lib and write script for convert to framework) but if you write used swift only one.
So you need create pod. Just create framework in xcode and add files for configurate your project to pod. It't easy, for example you can watch this, I create pod after create project

For swift you need to have Cocoa Touch Framework

Related

Sharing code between iOS Project and custom created iOS Framework

I have written a framework that make use of SAMKeychain. This frameworkA is used inside the an iOS project.
The iOS project in return has some additional classes that uses the same SAMKeychain. I am trying to find a way to refer the SAMKeychain in the framework and include as a dependency(But do not include SAMKeychain sources) inside the framework.
I tried referencing just the header files of SAMKeychain in the framework and try to build the framework but It failed with linking error _OBJC_CLASS_$_SAMKeychain
What is the best way to share third party code between the framework and iOS project
The solution was to use dynamic frameworks . So when frameworkA is made it should be dynamic and the Pods it contains that is SAMKeychain should also be dynamic to do that you use
use_frameworks! in Podfile which will create SAMkeychain.framework for the Pod SAMkeychain.
After the frameworkA binary is created in the iOS project you have to add both frameworkA and SAMKeychain.framework as embedded binaries. And this will work just ok.
Note that if you don't use use_frameworks in the Podfile it would generate a static library of the pod which will be included in the binary of frameworkA.
Hope this helps someone!

podspec with dependency to another ios framework project

I had developed a swift farmework to share with other developers(Lets name it B). This framework is using another ios framework project that I created recently with objective-c (lets name it A).
Now, I want to share framework B with cocoa pod. I wondering how should I link these two project in the podspec file. Does I need to share both of them with pod? or is there any other solution that just share project B?
I was having same question when I was trying to create a swift framework that is using obj-c framework, but didn't find an excellent solution.
So I've made a dependency in podspec file and now my swift framework can be installed by a podfile and it works fine. When I call pod install/update it installs/updates my framework and a dependency framework
The dependency can be created by one line
spec.dependency 'SomeOtherPod'
Check this link https://guides.cocoapods.org/syntax/podspec.html
Also you can check my podspec
The only thing that I don't like is that I have one warning in my project now:
Multiple build commands for output file
..../Build/Products/Debug-iphonesimulator/NMSSH/NMSSH.framework/Headers/NMSSH.h
Still trying to find how to solve it
Hope this will help you
You have 2 options:
1. Distribute both pods and use spec.dependency in your podspec file (see Woof's answer)
2. Add A source files directly to B's source files

How to use cocoapods in xamarin.ios

I would like to make use of couple of cocoapods in my xamarin.ios project.
But I couldn't find those cocoapods in Nuget which is package manager for Xamarin.
I heard we can compile a xcode project into a static library ... that is .a file and use it in xamarin.
But I am getting confused on how to convert the pods into a static library or something so that I can use those pods in my xamarin.
You cannot take the Pod directly and create a static library but you can although create a static library from the Pod project which already contains your pod. But to be honest the best solution will be getting the source code of the project and create the static library from there. Most of the Pods out there are open source so grabbing the source code from github should not be a problem.
Once you have the source code follow this example to show you how to create static libraries from there.
Once you have created the static library you just need to follow this tutorial to create a Binding library that can be used in Xamarin.
Unfortunately AFAK there's not support yet for Swift libraries to create binding libraries so this will only work with objective-c code.

CocoaPod and Unit Tests for Swift Framework

So I'm having trouble locating the definitive answer after trawling Cocoapods.org
I know Quick and Nimble are used for Unit Tests, at least for objective-C, however when creating a CocoaPod in Swift as a framework, I read somewhere there is only one choice, but what is that choice?
What is THE framework I have to use for my swift,framework cocoa pod to have it count as tested, as it's not XCTest obviously.
For a pure Swift CocoaPod you can use Quick/Nimble or XCTest. I recommend reading the excerpt here from CocoaPods.org in regards to creating a new Swift framework (including unit tests).
https://guides.cocoapods.org/making/using-pod-lib-create.html
I recently created a Swift CocoaPod using the "pod lib create" command and using only XCTest. Using the provided command line approach you can start a new project to include unit tests and a demo app, if desired and all the setup is handled for you. The only configuration I needed was to ensure the pod target had enable_testability = YES so that your unit tests can read your pod classes.

CocoaPod issue with test target

I have a helper class (GoogleHelper) in swift that uses the Google finance API where I use AFNetworking for Google API call. AFNetworking is imported using cocoa pods.
I need to test the GoogleHelper and need mocking.
For mocking to work, I have to add the GoogleHelper file to test target as well. and redefine a mock class in the test class.
class MockGoogleHelper: GoogleHelper {
override func getSymbol(text: String) -> String {
return "symbol"
}
}
The issue is that the test target has compiling issues with AFNetwork. I added the header files and the compiled pod library manually to the test target but the issue persist.
I have two questions?
how to make the cocoa pods add the dependency to the test target. I have used linked_with in my pod file but no luck
If there is any hint on the way I am setting my test wrong let me know as I think when I test my helper class it should not depend on the AFNetworking but I am not sure how to eliminate the dependency.
There are a couple of things you should do to get it to work:
add the test target to your pod file e.g. linked_with 'myprj', 'myprjTests'
in project/info/configuration for both debug and release select Pods.debug or Pods.release respectively.
you need to bridge your library if project is on swift and the library imported with cocoa pods is in objective c. to do so just try to add an objective c file to your test files and Xcode will automatically add the bridging header to your project.

Resources