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

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.

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.

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

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

Adding a GitHub framework to an XCode Project using Swift

Sorry if this is too basic, I'm a kind of a rookie on app development.
I've been trying to add this GitHub framework for SpriteKit easing to my XCode project. The only steps for installation (that doesn't require CocoaPods) the framework provides are: 1: Drag the Pod/Classes folder into your project. 2: Import the frameworks in the _Archive folder.
However, it doesn't seem to work after doing this. I can't import the framework into my swift files, and I can't use the actions. I may've done the 2nd step wrong, I may not have done it as it's supposed. I've searched all over the internet for ways to import a GitHub framework into XCode, but every answer seems to be different and specific for each case.
I think you may have missed the second step (you say there is 'only step'). The second step is to drag the framework from the _Archive folder. You can find it in the clone of the project folder. Also, try the sample project and see how it's organized. Make sure that you add the framework to the Link Binaries... section in the project Build Phases.

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.

Xcode - debugging library built outside project

I have a C library whose code resides in say /repos1/clib. I build that from the command line using the latest iOS sdk to create clib.a (including a debug build for the simulator) which I copy to an iOS project say in /repos2/proj.
I have been using this setup for several years. The old C library very occasionally might require some debugging and I was pleased by the fact that Xcode simply stepped into the library code that was outside the project (inside repos1) without having to do any setup - it just worked.
But this was up until a few Xcode versions ago. I am not sure exactly when it changed - perhaps when they moved from gcc to llvm? - since I very seldom needed to debug the C code, but for a while now I only get dissasembly when I try to debug the C library from the iOS project (including at least references to the C file name & line number). For the few times I need to debug it is very inconvenient (I create a temp project that includes the C code).
So, any idea why it worked before and doesn't now? Where should I look? Could it be the way I build the C library, maybe there was a flag in gcc I was using that does not have an equivalent in llvm (I can find and post the old build command I was using if it is relevant)? Is the issue in Xcode and there is a way to tell it where to look for the sources?
Thanks!
Edit: To make it clear, I can add the C library either as the source or as a subproject in Xcode, however for reasons that are out of scope this is not helpful for this specific project. So, can it work like it used to with older Xcode versions? If not, it would still be interesting to know why not.
The recommended approach is to create a library project in Xcode, one for iOS (there is a template for it), then when you get that to build add that project to your app, make sure the lib is a dependency and gets linked. There are many tutorials on the web how to do this.
Then as iOS evolves and new architectures (armv7s) arrive you simply update both projects.
I was struggling with the same issue.
I tried resetting in library/application project all options related to symbol stripping and copy application project to same truecrypt drive as library project but it didn't help.
In my case it appeared it was an app project issue. Same library could be debugged in another app project with source code so that was a clue.
I had more than one version of the same library in app project and set only target membership to choose which should be used. Not sure if that could affect my app project somehow.
Nevertheless after deleting all libraries and copying them to app project again I was able to debug libraries with access to source code.

Resources