Creating a Framework for iOS | raywenderlich.com

Learn how to build an iOS framework, which lets you share code between apps, modularize your code or distribute it as a third-party library.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/17753301-creating-a-framework-for-ios

This is great! I followed along with my own project and it was clearly explained. Could you help shed some light on how dependencies affect a Swift Package. In your example, if the CalendarControl Swift Package has a dependency on SomeOtherPkgA and SomeOtherPkgB, you would list those in the Package.swift config file. How does that affect the way your Calendar package is consumed? In a new project importing the CalendarControl package, I thought SPM would handle resolving those dependencies, but I had to add them manually.

1 Like

Hi
Sorry for the late response; I was on vacation.
If you publish your SwiftPackage on GitHub, for example, and on Package.swift, you have added your dependency; it should be fine when you’re trying to add your package to any project.

Thanks. It appears, however, this is not true for binary targets. I haven’t been able to find any evidence that this is supported by Xcode and SPM. When listing your targets in your package manifest and including a binary target, the .binaryTarget class does not have an option to list dependencies. I did find a workaround, though: Issue with third party dependencies inside a XCFramework through SPM - #2 by rockebee - Using Swift - Swift Forums

Have you heard if official support for this is in the works?

Yes, You right, there is no such a place to have a clear path for that, and since this topic was released recently on WWDC 20, there might be an update for it in the coming one.

HI, there was another version of this tutorial talking about how this was done using cocoa pods, and the framework was a UI circle for progression, but I cannot find it, some people used that to develop a framework, and now it is missed and is difficult to track the steps to do maintenance to those projects, but that info is no available in this site anymore, is there any way to access to it?

Thanks!

Hey,
I was looking to find a way to let you to have the old version of it but since we push the update there is no way to give you access to the old one except one way which is using the web archive, here is the link:

hi, i have some problem that archive framework…
when i open terminal and enter order that article copy, xcodebuild archive \ … … …
but archive failed, and error message showes like bellow.


BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

but there archive failed error like bellow.

 ** ARCHIVE FAILED **

The following build commands failed:
	CompileSwift normal arm64
	CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)

i use intel i5 imac. i think this might be m1 mac and intel mac confused… and i don’t know how to fix it.
can you tell me how to fix this issue???

thanks a lot.

Hey odyflame,
I’m so sorry for the late response.

I just downloaded the material and re-ran that command by using the one it’s already mentioned in the tutorial, and everything is fine and working as expected ( I’m using 2,6 GHz 6-Core Intel Core i7).
Then make sure you are following all the steps from the article, or if you want me to investigate more, please send your project to me on my email emadgnia@gmail.com, and I’ll try to build it and let you know what’s the issue.

I was wondering if the binary packages need to be .zip or can have other formats like .tar.xz. I couldn’t find particular info on the docs.

Great article by the way, thanks!

I got stuck at the adding files step in embedding your binary. It would just import the xcodeproj file but nothing else. I had to do the “Apps with Multiple Xcode Projects” section linked below instead of “Apps with an Xcode Workspace and Multiple Xcode Projects” which the tutorial seems to use. Not sure why, just sharing in case anyone else is stuck on this issue. Otherwise the tutorial was great!

I have been following the above Framework tutorial using Xcode 13 on a MacBook m1.

I have a basic problem on which I hope to get some feedback.

When I create a framework I get the Framework with only one attached project.h file.
The framework builds successfully.
However there is no Contents folder produced or any output file? Is this a bug with XCode13?
My understanding is that this output file contains binary outlet code stored on your Mac?

The project.h file says “In this header you should import all the public headers of your framework” This does not appear to be a requirement in your tutorial.

Your tutorial is written very clearly but I am stuck at the beginning.

Any advice would be greatly appreciated.

1 Like

I am also stuck when trying to run this with XCODE 13.0 on Big Sur

Specifically I am stuck on the Embedding Your Binary section.

In the steps to fix, the Products section is not shown for the project and therefore no framework.

There are a couple of minor inconsistencies too, so far.

Chris

1 Like

Hi,

I have created a static framework with some third-party framework (pod), while converting my framework into xcframework all of the pod dependencies are added to xcodebuild archive. But I want to add these pods as dependencies to this framework. is there any way to do this?

Thanks

The products are not shown in Xcode 13.
You could fint the product on Product > Show Build Folder in Finder
Then you could move the framework to Xcode and it will work, please update the tutorial.

1 Like

Hey @emadgnia ,
I am also having same error like @odyflame one. I googled and tried but not so helpful. I am using 2.6 GHz 6-Core Intel Core i7, MacOS Monterey and Xcode Version 13.1 (13A1030d). Please help me .
I have mailed you regarding the same issue.

Thank you

Is BUILD_LIBRARIES_FOR_DISTRIBUTION correct? Half of tutorials on the web use BUILD_LIBRARY_FOR_DISTRIBUTION instead.

Hi, when we build the CalendarController target, what do we chose, do we build for “Any iOS Device (arm64)” or “Any Mac (…)” or one of the iOS simulators such as iPhone 13, etc? In your tutorial, it doesn’t specify.

Which one do we move?

Debug-iphoneos or Debug-iphonesimulator

Thanks

1 Like

Hello!

Great tutorial, it was working superb until I ran into an issue…

In order to build and run the project with this architecture on my physical iPhone, I need to move the Embed Frameworks phase as last phase. Otherwise, after building successfully Xcode will display the message “Unable to install” with the details “No code signature found.”.

I wonder why this does not occur when I move the Embed Frameworks phase as last phase? Our last phase is a remove architectures phase needed for other frameworks…

Note: I am using the tutorial up to the last step, thus am using an SPM to distribute the framework.