#if canImport() not working properly with CocoaPods. Serious issue - ios

we are experiencing really strange issue, which creates problems in our production code. Basically, we have created a framework, which has few separates optional frameworks. Right now, we access code from the framework with the following logic:
#if canImport(optionalFramework)
firstMethodFromTheFramework()
secondMethodFromTheFramework()
#endif
The problem is that, then we distribute our main framework with CocoaPods, even if client integrates additional Subspec, our code cannot reference additional frameworks.. so it does not import frameworks and does not call optional methods. So it does not work completely and creates tons of problems... We simply don't get it, why IOS development does not allow such features and such architecture?
​
It is much better to modulize frameworks, instead of creating gigantic frameworks, which would only increase size and complexity..
Maybe there are other ways of accessing framework from optional frameworks, if client integrates them?
​
We really feel kinda unsure about this whole situation and it is crucial for our whole project.
​
I will clarify one more time: our main framework does not include optional frameworks at all. It just uses #if canImport() flags. Client should be responsible for adding Pods and then framework should automatically start executing code

I have the same problem and it solved for me by the following :
install the optional pods in your framework -lets say it's Alamofire-(you will remove at the end) so you can find there path in both files
yourFramwork.debug.xcconfig
yourFramwork.release.xcconfig
from FRAMEWORK_SEARCH_PATHS copy this "${PODS_CONFIGURATION_BUILD_DIR}/Alamofire"
and from HEADER_SEARCH_PATHS copy this "${PODS_CONFIGURATION_BUILD_DIR}/Alamofire/Alamofire.framework/Headers"
put what you have copied anywhere lets say note file
now remove the pod (Alamofire) from the framework podFile and run pod install again
manually past what you copy in both files:
yourFramwork.debug.xcconfig
yourFramwork.release.xcconfig
as they where ,done
right now if you add your framework to another project and install the optionalFramwork in the that project podFile every thing should goes fine
and #if canImport(optionalFramework). should work as you need
hope that solve your problem

Related

How to add or read Google calendar events iOS [Swift] without using Cocoa Pods

I am currently working on integrating Google Calendar into my iOS project which uses GoogleAPIClientForREST And GoogleSignIn libraries. Project Git can be found here. I am able to add or read all my Google calendar events.
However, I have been asked to make it work without using Cocoa Pods. I have added all the necessary frameworks by dragging and dropping into my project, it builds and runs but I'm getting a crash at this line (attached screen shot for ref) GIDSignIn.sharedInstance().scopes = [kGTLRAuthScopeCalendar] .
Here's working screenshot where am getting the kGTLRAuthScopeCalendar element in array. (Using Cocoa Pods)
Here's screenshot where am getting a crash because the kGTLRAuthScopeCalendar element in array has 0 values. (Without Using Cocoa Pods)
Does anyone have any idea what I might have missed, or am I wrong in my implementation without CocoaPods if yes, how?. Please help.
SO links previously referred: 1. How to Create events using Google Calendar API iOS Swift , 2.https://code.tutsplus.com/tutorials/ios-sdk-working-with-google-calendars--mobile-19155
Does anyone have any idea what I might have missed, or am I wrong in my implementation without CocoaPods if yes, how?
Cocoapods is just a dependency manager and distribution mechanism — it doesn't add any actual functionality to your code on its own. You could simply remove the Podfile from your project and you'd be left with a working project that no longer "uses Cocoapods."
One of the lovely things about a dependency manager like Cocoapods is that it manages not only the things that your project needs directly, but also the things that those dependencies need, and so on. There are only two pods listed in your Podfile, but your Podfile.lock shows about 18 pods because the two that you use directly each depend on other pods.
I don't think there's nearly enough information in your post to let us really understand what specific thing(s) you've missed in removing Cocoapods, but from your screenshot it looks like you only have about six frameworks installed in your project while, again, your Podfile.lock shows many more pods than that. It may be that some of the frameworks you need are embedded inside top level ones in your project, but the fact that your project doesn't work correctly even though you're presumably using exactly the same source code is a strong indication that you've left out one or more of the frameworks you need.
Go through the list of pods in Podfile.lock and make sure that the framework each one specifies is included in your new project.

Using Cocoapods with custom framework that also needs third party libraries

I've been running into a bit of a problem trying to find a set up that would work for my situation:
I'm building 2 iOS applications and a framework that's being shared between the 2 apps. Lets call the apps app A and app B.
So for both apps A and B I have cocoapods set up and the shared framework is being added as a submodule. I didnt want to create a pod for my framework cuz it's being developed at the same time(is it a good reason to not create a pod for it?).
So everything is fine till the framework needs its own third party dependencies, since I can't use cocoapods for the framework as it's being added as subproject into project A and B' workspaces, I had to do a "dirty" job of just embedding the framework's third party libraries into its project just to keep going.
But obviously this is not going to scale well, I was wondering if any of you guys have had similar situations and how did you go about managing it? I was thinking maybe using Carthage for the framework to keep track of the dependencies and for the project A and B still us Cocoapods.
Any pointers would be much appreciated, thanks
Let me know if you need any clarifications or if I'm missing something.
I've found something like this https://stackoverflow.com/a/26168055/8529947
but the thing that I'm not sure about this approach is doing this will modify build settings of the shared framework which is not a good idea since both project A and B will be modifying the shared framework build settings at the same time. Is that the case or am I missing something here?

Can't Use "Vendored Framework" CocoaPod Inside Workspace Playground

I've created a sample project illustrating my issue here.
In summary, I'm trying to use a "vendored framework" CocoaPod inside a workspace playground. I think this is possible but requires a bit of fiddling with project settings, and I can't quite figure out what to change.
To observe the issue in the sample project, do the following:
Open CocoaPods-Test/CocoaPods-Test.xcworkspace in Xcode.
Pods should be installed and committed in the repository, but can run pod install if necessary.
Note that the CocoaPods-Test target builds and runs successfully, importing PromiseKit and TwilioChatClient pods.
Navigate to Playground.playground within the workspace.
Note that the playground executes fine while importing PromiseKit but if TwilioChatClient is imported, playground execution fails with "no such module 'TwilioChatClient'".
After reading the following resources:
https://github.com/CocoaPods/CocoaPods/issues/5334
https://github.com/CocoaPods/CocoaPods/issues/5215
https://github.com/CocoaPods/CocoaPods/issues/5563
https://github.com/CocoaPods/swift/issues/3
https://github.com/CocoaPods/CocoaPods/issues/4135
https://github.com/CocoaPods/CocoaPods/issues/2240
https://github.com/CocoaPods/CocoaPods/issues/6669#issuecomment-300188519
https://guides.cocoapods.org/using/troubleshooting.html
https://www.objc.io/issues/6-build-tools/cocoapods-under-the-hood/
I think the issue is probably related to the fact that TwilioChatClient is a "vendored framework" (see its podspec), which means a pod target is not created for it. After reading the above resources, I feel like a solution is within reach, but I can't quite figure it out.
While the sample project here illustrates what I think is the underlying issue, the issue that prompted me to create this example project is just a small bit more complicated.
In my project, I create a framework target containing all my app's code (so it can be imported into my app and also into my playgrounds using app resources). This framework then has pod dependencies, including PromiseKit and TwilioChatClient. The execution error in the playground is different ("Couldn't lookup symbols" instead of "no such module"), as I am not importing the CocoaPods module directly but my framework which uses the pod framework.
I suspect if I can solve the "no such module" issue, it will help me solve my "couldn't lookup symbols" issue.
Finally, this seems like a good opportunity to make an open source contribution others don't seem to have wanted to do (see discussion here). Tangentially, I'd love to contribute but just don't feel like I understand what exactly is going on with CocoaPods, the Xcode build process, etc., after reading about it a bit (e.g. here and here). Any references to help understand the Xcode build process and what CocoaPods is doing under the hood are appreciated. It seems like the resources I've found are either "a very high level overview" (which I get), or "digging through the source code", with not a whole lot in between.
If you must have this work, I came up with a workaround by creating a framework target inside the Pods project which is named the same as the vendor framework, and uses all its headers publicly, using the framework as a sole dependency. I have forked your GH example and linked it here.
It's not the most elegant solution, but it will help you out in a pinch.
UPDATE
Build "fake" framework first, then build app target, then go to playground.

Podfile usage for iOS apps

I'm very new to using podfiles and have a bit of confusion around how they work and what I need to do to use them. I have followed the 'Getting Started' section on the main website and have successfully created a podfile and run install to pull in the dependencies. The questions I have are as follows:
I see a new section in my project which appears to list the pods i've requested, however they all seem to be in red - is that normal? If not what have I done wrong / what do I need to do?
In terms of some of the Core iOS frameworks (e.g. UIKit, Foundation, etc.) do I still need to manually import them as frameworks into my project? Can I add them to my podfile so I can manage everything in a single place? If so how (does the syntax vary/differ?)?
They appear as red because this frameworks not built yet. After you build project they should look normal.
Yes, CocoaPods only handle third-party dependencies.

Creating framework that requires (depends on) another framework

I'd like to create a framework using Cocoa Touch Framework Project in Swift. However, I'm building this framework on top of another framework called RNCryptor, which is Objective-C based. I've seen various tutorials on how to create a framework in Xcode but none has covered a framework with its own dependency.
I tried to create a framework project and then using CocoaPods to manage its dependencies. However, there are errors appeared: 'Check Dependencies' Unable to run command...'
So the question is: is it possible to create a framework on top of another framework in Xcode. And if so, how?
Frameworks should never embed other frameworks directly. This leads to collisions if the importing project or any other framework also includes that framework. Instead, you need to tell your consumer that they also need to include your dependency. CocoaPods will do this for you automatically, so you should let it. (If you're having trouble with CocoaPods dependencies, you should ask a question about that and get it cleared up. The whole point of CocoaPods is to manage these kinds of things.)
Note that I will be releasing the Swift version of RNCryptor into beta today (or tomorrow, but I really hope today). This version bridges to ObjC and will be the preferred version going forward. (The ObjC version will continue to be available of course for projects that cannot or don't want to include Swift.)

Resources