Two related iOS apps in one CocoaPods workspace? - ios

I am working together with some friends on a iOS project.
We are using CocoaPods for integrating third-party code (Facebook-iOS-SDK, ..) and sync the whole Xcode workspace (including the Pods Project) with Git and bitbucket.
Everything works perfect and we are very happy with this setup.
The only problem is, that we have to build a second application and the two apps will share a lot of common code.
Does it make sense to just add a second target to the workspace or is it better to create a private pod?
Other possibilities? We want't to keep things as simple as possible...

Related

Framework using cocoapods inside other framework using cocoapods inside app project

I have a app which historically has grown a lot and to be a bit cleaner and to have the option to give out code to third party developers in the future, I was thinking about splitting my project into multiple projects which I then could export as a framework.
Currently everything is in one big project. I have:
4 App targets
Shared view controllers
Shared web services
Shared model classes
Shared utility classes
Shared extensions
Shared protocols
The thing is that not every web service is used in every app. Not every protocoll is used in every app. Not every extension is used in every app and so on.
Now correct me if I'm wrong but can't I put, for example, the web services in their own framework and then use the framework in the project where I have my app targets?
Can I do the same for a "core" which contains all utilities, extension, protocolls and models?
Can I then use the "core" in the webs service framework as well as in the app targets?
What would such a structure look like? I already tried creating two framework projects and then use one framework inside the other but I cant build it. Is it because I would need to use Cocoapods inside each of the framework projects? Is that possible?
The web services for example would need "RxSwift" and "Moya" but the "Core" would also need "RxSwift".
Do I have a wrong thinking here? Shall I only use one Core framework and put everything in there which is shared? I'm confused and probably lack the deeper understanding of how the frameworks work.
I'm using CocoaPods and have separate from main app web service and core frameworks. This way it looks in the project:
Lets start with core because even web service depends on it. I call it Common instead of core and it is available on GitHub. It contains multiple subfolders which represent frameworks they extend. And there are two podspecs.
CommonExtended contains functions that are not available in app extensions (for example in Today Extension) and depends on Common. So, splitting core into two separate frameworks provide a way to use it in both main app and app extensions. Although Common is available on GitHub, I download and use it locally (but it can be downloaded from remote whenever you update your pods, you just need to specify remote address)
web service is a local folder which is called Api and its podspec looks this way:
As you can see, it has such dependencies as RxSwift, Moya and Common (the desired behavior from your question - framework contains framework).
So, whenever I need to use any of the frameworks in an app or its extensions - I just specify what kind of framework is required as dependency:
Then just import your frameworks and use them:
import Api
import Common
import CommonExtended
P.S. This is just an experiment, I'm not a CocoaPods professional. But it works for me.
Edit. Local pods are easy to update. You just make changes and see them in your project (as I remember Cmd+B on main project makes the changes to be visible). But this only works with files in local pod which already exist. If you need to add new file to a local pod - run pod install to make this file visible.
All the local pods are 100% local and they live in the same repository as main project. But Common is a remote repository which is downloaded locally. Why? Because it is used in different projects. So, on each machine you have to write its own path to Common in podfile. This link provides a way to define a path to Common on each machine and never change podfile again. Don't forget to commit Common changes to the remote. Other local pods will be committed with the project automatically.

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?

iOS - update a framework

I built an app that uses a third party SDK. Recently I had to update the SDK with a new version. I removed the framework files from my application folder, copied the new ones, added them to the project, but it seems XCode is caching the old version.
I tried Clean, tried to delete Derived Data, nothing works. At this point it seems the only available option is to recreate the project and import all the source files. Obviously I am not keen on that. There must be an easy, fast solution to this issue.
Any clue?
Cocoa pods are easy to use and install.
CocoaPods is the dependency manager for Objective-C projects. It has
thousands of libraries and can help you scale your projects elegantly.
Ultimately, its goal is to improve discoverability of, and engagement
in, third party open-source libraries, by creating a more centralized
ecosystem.
However the frameworks need to be compatible with cocoa pods which most libraries are. You use terminal to install. This site may give you an idea how to install it.
Fixed it. I deleted all copies of the old SDK, whether or not they were in my project folder. Seems like XCode was linking to one of them... Another mystery.

How to share utility class among iOS projects?

Should I create iOS 8 new feature called Frameworks / Extensions to share a simple Utility class used among more projects?
How do you share common application logic? I thought I will just drag a swift textfile in projects without checking Copy items if needed checkmark. Am I doing right?
I found here a promising tutorial with fancy inbuilt animation: http://www.raywenderlich.com/65964/create-a-framework-for-ios
And this youtube video tutorial is useful too: https://www.youtube.com/watch?v=86cPaa3FrRg
You can surely do that about have a common file in a folder and imported in several projects but that doesn't look like a good approach.
What if you start to make breaking changes over time? Some projects can work and others not,
What was the last version that worked for each project?. As is shared changes happens to all project without fine grain control
Would anybody that work in a team with you be able to compile the project? How you share with other people those not copied files necessaries to run the project.
So my answer would be to use a new repo for the shared code and make a framework from it and share the frameworks across projects tracking the version. Or if you prefer use git submodules or git subtree.
Finally, Cocoapods with the new use_frameworks! feature in the 0.36 version solve all these problems for swift (as they did before for Objective-C) making possible do to your our public or private frameworks in swift as you could share static libraries before.

Separate Xcode Project

We have 3 apps that we maintain, that all use the same menu controller and Core Data model. In addition, one of the apps uses several views and controllers from one of the apps. It's getting to the point that we need to find some way to separate into different projects to prevent painful Xcode project merges. Right now all the code is mixed in together and each app has its own target in one Xcode project.
Is there any way we can separate the project easily into different projects that have AppA, AppB, and AppC where AppB and AppC depend on AppA?
Depending on how each app is different, you can create different targets in your Xcode.
Here's a docs on how you create Xcode targets.
If that does not suit your need, you can create multiple projects and reference files from other projects. I really can't tell what you'd need without more information.
Maybe use cocoapods.
You can make your own (private) pods for the various files that your projects rely on and then keep them updated in their own repository, and then the projects can include the pod and update it when needed. You can also point specific projects to specific branches of the pod repo etc.
(Not sure whether Core Data is supported in pods yet though, might be)

Resources