17.2 C
Canberra
Monday, October 27, 2025

make a Swift framework?


Making a Swift framework should not be laborious. This tutorial will provide help to making a common framework for complicated initiatives.

What’s a framework?

A framework is a hierarchical listing that encapsulates shared assets, comparable to a dynamic shared library, nib information, picture information, localized strings, header information, and reference documentation in a single package deal.

So in a nutshell, a framework is a extremely reusable element in your apps.

make it?

There’s an article about Xcode conventions which can provide help to arrange your initiatives, you need to examine that first, in the event you haven’t earlier than.

Conventional approach

There’s a conventional solution to make a framework in Xcode. I’m going to create a shared framework for all of the apple platforms (iOS, macOS, tvOS, watchOS), which goes to be able to logging issues to the usual console.

Let’s make the challenge:

  • Create a brand new challenge utilizing one of many framework targets
  • Comply with the directions fill & identify all of the fields
  • Add all the opposite platform framework targets
  • Rename all targets in response to the platform names

Now in Finder:

  • Create a Sources folder and transfer all of the Swift and header information there
  • Create an Property folder with platforms subfolders
  • Transfer all of the Information.plist information into the right platfrom subdirectory
  • Create a Assessments folder and transfer check information there

Again to Xcode:

  • Take away each group and add the brand new Folders from Finder
  • Test that each goal has the right information (framework & checks)
  • Contained in the header file, exchange UIKit depencency with Basis

The aim is to realize a construction considerably like this:

make a Swift framework?

Challenge settings:

  • Choose the right plist information for the targets
  • Set your bundle identifiers (use my conventions)
  • Setup platform variations (recommendation: help 1 older model too)
  • Setup the plist information for the checks from the construct settings pane
  • Set the product identify (Console) in your framework construct settings
  • Test your construct phases and add the general public header file.

Scheme settings:

  • Go to the scheme settings and setup shared schemes for the frameworks
  • Collect protection information in the event you want it
  • Write your framework you should use Swift “macros” to detect platforms

NOTE: There’s a flag in Xcode to permit app extension API solely, in case you are embedding your framework inside an software extension it needs to be enabled!

Congratulations, now you may have your model new Swift framework made within the conventional approach. Let’s proceed with a neat trick.

Common cross platform framework

It’s potential to create a multiplatform single scheme Xcode challenge with cross platform help for each platform, but it surely’s not really helpful as a result of it’s a hack. Nonetheless a number of open supply libraries do the identical approach, so why shouldn’t we.

  • Delete all of the targets, schemes, besides macOS!!!
  • Rename the remaining goal, scheme (we don’t want platform names)
  • Use the challenge configuration file, set the xcconfig on the challenge
  • Delete Information.plist information, use one for the framework and one for the checks
  • Rename bundle identifier (we don’t want platform names there too)

WARN: States might be blended up in case you are constructing for a number of platforms, nonetheless this can be a good clear solution to help each platforms, with out duplications.

use a Swift framework?

Embedding your framework is essentially the most simple factor to do. You possibly can merely drag the framework challenge to a different Xcode challenge, the one factor left to do is to the embedded the framework into the appliance. You possibly can go to the embedded binaries part inside the final challenge data tab and add the framework as a dependency.

Swift Package deal Supervisor

With SPM, you must make a Package deal.swift file first, you then’ll be capable to construct your targets with the swift construct command. Now that Xcode helps the Swift Package deal Supervisor, it’s very easy to combine third occasion frameworks by utilizing it.

You possibly can obtain the ultimate framework examples from GitHub.

Just remember to don’t miss out my deep dive into swift frameworks publish.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles