iosswiftxcodecocoapodsswift-framework

Xcode Create a swift framework that itself uses cocoapods


I'm still relatively a beginner. I'm trying to create a uber type app that uses firebase database (installed via cocoa pods). I'm creating an app for drivers and another for riders. I'm also trying to start out right by structuring my app as best i can to begin with.

In the riders app, I created a database handler singleton to control access to the database including functionality to add the rider to the database. A common firebase database is shared by both apps. Rather than have both apps have separate database handlers (and various other independent handlers), I've created an independent swift framework to hold the handlers.

I've added my swift framework to the top level of my workspace in both the rider app workspace and in the driver app workspace (by dragging in the framework xcodeproj file) and gone through all the processes I've read about to build the framework to a generic device and copy the framework to the actual app embedded binaries etc. Independently both app workspaces are working properly .... however ... i have 2 problems at this stage

  1. if i try to open both workspaces at the same time (ie work on the rider app at the same time as working on the driver app), Xcode gives me a workspace integrity error basically giving error "couldn't load xcode project (ie the framework project) because it is already opened from another project". the app still runs ok but the error (red error) remains. how can I fix this?.
  2. I want to use FirebaseDatabase within the database handler framework itself but even though I have FirebaseDatabase installed in the main app, the framework can't see it ie import FirebaseDatabase line is showing "no such module". I also tried installing FirebaseDatabase via cocoa pods separately in the framework project and am still getting the same "no such module" error. How can i get the framework code to see the required cocoa pod frameworks

Solution

  • Having a shared framework project outside of two app projects, but included in their workspaces can cause problems. Editing the framework in one workspace may break the app in the other workspace if the change is a major one.

    I think you have two options. One is that you keep the framework app in a central repository and check it out into the app projects. This lets each app project use the version of the framework they are comfortable with and if one changes, the other doesn't see those changes until you tell it to update.

    Another option is to switch to a single workspace with both apps and the framework in it. Effectively saying that you will always be working on both at the same time and they will always be in sync.

    I can't say what the issue is with not finding the framework as I don't use CocoaPods, but I'd be checking all the framework search paths in each project settings to see if they are searching the right directories for the compiled frameworks. You should not be copying any dependency frameworks in the framework target, but all of them will need to be copied in the app targets.