how can i create a framework from existing project? - ios

i have a huge project written in objective c with many pods in it and i would like to export the entire thing as a framework. is it possible? i have never did such thing before. my project also has a big assets library and frameworks inside of it like Firebase/Fabric/Facebook and much more. how will i handle the info.plist file of the existing project in the new framework?
i have tried this tutorial
https://www.raywenderlich.com/126365/ios-frameworks-tutorial
but it doesn't mention having previous pods in my existing project.

Related

xcode how to develop with frameworks

Thanks for spending time reading my question.
I've been working as an iOS developer for more than 2 years and today I still feel shame because I don't know how to deal with frameworks. I've build some projects using my own frameworks, but I've never understood exactly what's the best practice doing this.
Lets see the following example:
Project -> FrameworkA -> AFNetworking - Charts - FMDB - more
So, I have a big FrameworkA with mostly all the app behavior and then a small project referencing this FrameworkA and customizing just icons, texts and images. I use to manage dependencies with CocoaPods and I would like to use it with FrameworkA. By this I could reference external libraries easily, but it seems it doesn't work for frameworks, only for projects. So, my questions is: how can I add AFNetworking, Charts, FMDB, etc to my FrameworkA and then reference the framework form my project?
I appreciate if you can give me some idea using CocoaPods or any other dependency manager. I don't like the old way by doing this manually.
I hope my case is clear.
Thanks!
It sounds like you are asking how to embed external frameworks such as AFNetworking into a framework you are developing, and then use that framework in your app.
This is what's known as embedded frameworks where one framework is stored within another. Generally speaking it's not a great idea and should be avoided because it can cause version clash issues.
The way I'd recommend doing this is to use CocoaPods or Carthage to link the external frameworks (AFNetworking, etc) into your framework project. But do to try to embedded them.
Then in your app project, again use CocoaPods or Carthage to link in your framework (you won't need to link the external ones unless you are directly using them in the app code). Then add the necessary build steps to copy both your framework file and all the external framework files to the finished app's framework directory.

How to build an iOS Framework with a dependency on another without creating an Umbrella Framework

I am trying to streamline my development by creating some re-usable Frameworks which incorporate features I commonly re-use in multiple projects.
However, having setup one of my Frameworks I have encountered a problem, the classes have a dependency on the Firebase framework. Having read the Apple docs it's not recommended to create an Umbrella Framework (one which embeds another) especially if you do not have ownership of the embedded Framework (which I do not).
So the question is:
How can I create a Framework project which allows me to build the Framework without including the dependencies which would create an Umbrella Framework. I presume this is what people like Firebase do because when you add their Framework there are others you have to add to your project as well. I can't quite see how you would configure a project to allow you to build the Framework without errors but not include the dependencies.
For reference I am using the latest Xcode and need to support iOS 8 and above.
Thanks in advance for any thoughts / suggestions on this
For the benefit of anyone who is struggling with the same issue, the answer is much simpler than I had anticipated.
The Frameworks are linked dynamically and simply adding a Framework to the project for your own framework will not cause it to be embedded in the output file and therefore not generate an Umbrella Framework. You don't actually need to do anything. Any Frameworks that are required by your own Framework can be included in your project so that you can compile your own Framework, and will also need to be included in any projects that utilise your Framework.

Is it possible to create a standalone distributed Swift Framework?

I have a scenario where I need to package some common code into a Swift only framework. I have found many tutorials on how to do this but all involve creating a framework within an iOS app. My goal is to:
Create a seperate Framework project
Build and produce a .framework file
Copy that single file(without all the source files) into some iOS app project, add it under "Linked Libraries" and use it.
Question: Is this possible or do I have to include all of the Classes that are part of the framework?
I have added a framework project to an iOS app and had success using it because all the source code was in the Framework project. I tried to copy that .framework file alone to a new project and use it but when trying to access the classes or instantiate the contents of the framework I couldn't even-though whatever needed to be declared as public was.
Appreciate any help...

Adding a custom Framework to an Xcode project

I decided to try to make a Cocoa Touch Framework. Making it worked fine, but I am having trouble adding it to a project. After searching through a lot of SO posts and looking at Apple Forum threads I decided to try this from the Docs:
Add a framework bundle to a project in order to incorporate the
framework’s features into your product.
In the project navigator, select the project or group within a project
to which you want to add the framework.
Choose File > Add Files to “”.
Select the framework bundle, and click Add.
The frameworks you add this way are third-party-built bundles
containing the framework’s object code and runtime resources. See
related articles for information about linking to a framework without
adding it to the project.
After you add the framework, Xcode configures the targets in your
project to link them to the framework just added.
It still doesn't work. I am getting a No such module 'Scaffold' error for everything I try, I have checked spelling, but that is not it. Can someone explain how this works? I might just need clarification on how this is done.
Links I have looked at:
Create and import swift framework
Xcode error when I add a framework
Adding a framework to XCode 4
Xcode 5.1 compiler errors after adding a framework
Add a framework to an existing project without using cocoapods
What is the process for creating a Framework?
Hey I do not know if it is too late to answer this question, but due to the fact that I am facing same issues right know I would recommend you to check the Build Settings of the project where you import your framework
You should check the "Framework Search Path" and if the framework is at Swift and you import to an obj c project check YES to "Always embed swift standard libraries"
More or less the problem I think is in the Build Settings

Reference code in a separate project in XCode 4.2

I'm working on an iOS app where I use third party libraries. I want to migrate my project to use ARC, but the third party libraries are still using the old memory management. So I want to separate third party code and put it in a separate project without ARC, and then somehow link that project into my iOS-app project, so that they will be built together using the same configuration.
Is this possible to do in a very simple way, or am i better of just turning off ARC for the individual files? (seems very tedious..)
Can I use a workspace? Where one project is my iOS app and the other just contains third party code?
I've played around a bit and googled a lot, but there just doesn't seem to be any simple soultion, or am I wrong?
So I figured it out myself, with a lot of help from different blogs. Something this basic should be more trivial and well documented... But here we go, this is what I did to get a library for AsiHttpRequest:
Create a new iOS project. Select the 'Cocoa Touch Static Library' template. Call it whatever you like. You don't want to tick 'Use automatic reference counting', since AsiHttpRequest does not support it.
Select a location for your library project (will matter later on).
Delete the default .h- and .m-file created by Xcode.
Drag and drop the AsiHttpRequest files into the project
You can add the frameworks that AsiHttpRequest is dependent of, but you will have to add them to your main project anyway, so it is not necessary.
Try to build the project, it should do so without errors.
Open your main project
From finder, drag your library .proj-file into your main project (in Xcode, so that it 'lands' onto the main project file)
The library project should now appear under your main project (still in XCode). It should be expandable and you should be able to see the library project files as well. If it doesn't, try closing all open projects and reopen the main project.
Select the main project, and select target. Under Build Phases - Link Binary With Libraries, click the +-sign.
In the list of frameworks you should see your library project (called something like libname.a). Select that file
The newly added file might appear red in the list of frameworks, don't worry, it works anyway. Guess it's a bug.
Still under target, go to Build Settings
Under Header Search Paths add the relative search path to where the library .h-files are. This is relative to your main projects .proj-file. (For example ../some folder/libproject/)
Hopefully your main project will build without errors and the library project will be built at the same time, using the same configuration as the main project.
I have no idea if this is a good approach or if there is some easier way to do it. However, I like this, since I can use the library project in several projects. And if I want to update the library project, I only have to do it in one place, and the other projects will be updated as well, since they all reference the same project.
Edit1:
I had some problems with library projects using objective c categories. I received unrecognized selector sent to instance errors in runtime when trying to call those methods. This problem was solved by following the answer given here.
Go to build settings of the target in the main project and add -ObjC to the entry called Other Linker Flags
Edit2:
I found this template for creating Universal frameworks. I haven't tried it, but I guess something like this would work as well.

Resources