Wednesday, March 22, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home Swift

How to make a Swift framework?

learningcode_x1mckf by learningcode_x1mckf
October 11, 2022
in Swift
0
How to make a Swift framework?
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


2017/10/23

Making a Swift framework should not be laborious. This tutorial will enable you to making a common framework for advanced initiatives.

Swift

What’s a framework?

A framework is a hierarchical listing that encapsulates shared sources, 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 part to your apps.


Easy methods to make it?

There’s an article about Xcode conventions which can enable you to manage your initiatives, it’s best to verify that first, if you have not earlier than.


Conventional approach

There’s a conventional solution to make a framework in Xcode. I’ll 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 mission:

  • Create a brand new mission 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 keeping with the platform names

Now in Finder:

  • Create a Sources folder and transfer all of the Swift and header information there
  • Create an Belongings folder with platforms subfolders
  • Transfer all of the Information.plist information into the proper platfrom subdirectory
  • Create a Assessments folder and transfer take a look at information there

Again to Xcode:

  • Take away each group and add the brand new Folders from Finder
  • Examine that each goal has the proper information (framework & assessments)
  • Contained in the header file, change UIKit depencency with Basis

The purpose is to attain a construction considerably like this:


Mission settings:

  • Choose the proper 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 assessments from the construct settings pane
  • Set the product identify (Console) in your framework construct settings
  • Examine 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 knowledge in the event you want it
  • Write your framework you need to use Swift “macros” to detect platforms

There’s a flag in Xcode to permit app extension API solely, if you’re embedding your framework inside an utility extension it needs to be enabled!

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



Common cross platform framework

It’s attainable to create a multiplatform single scheme Xcode mission with cross platform help for each platform, however it’s not really helpful as a result of it is a hack. Nonetheless a number of open supply libraries do the identical approach, so why should not we.

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

States will be blended up if you’re constructing for a number of platforms, nevertheless it is a good clear solution to help each platforms, with out duplications.



Easy methods to use a Swift framework?

You might also like

Hummingbird routing and requests – The.Swift.Dev.

Building a Scrollable Custom Tab Bar in SwiftUI

Beginner’s guide to server-side Swift using the Hummingbird framework

Embedding your framework is probably the most easy factor to do. You may merely drag the framework mission to a different Xcode mission, the one factor left to do is to the embedded the framework into the appliance. You may go to the embedded binaries part inside the final mission data tab and add the framework as a dependency.


Swift Bundle Supervisor

With SPM, you need to make a Bundle.swift file first, then you can construct your targets with the swift construct command. Now that Xcode helps the Swift Bundle Supervisor, it is very easy to combine third get together frameworks through the use of it.

You may obtain the ultimate framework examples from GitHub.

Just remember to do not miss out my deep dive into swift frameworks put up.




Source link

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

Hummingbird routing and requests – The.Swift.Dev.

by learningcode_x1mckf
March 17, 2023
0
Hummingbird routing and requests – The.Swift.Dev.

Routing on the server facet means the server goes to ship a response primarily based on the URL path that the consumer referred to as when firing up...

Read more

Building a Scrollable Custom Tab Bar in SwiftUI

by learningcode_x1mckf
March 10, 2023
0
Building a Scrollable Custom Tab Bar in SwiftUI

Whether or not you’re making a social media app or a productiveness device, the tab bar interface can improve the consumer expertise by making it extra intuitive and...

Read more

Beginner’s guide to server-side Swift using the Hummingbird framework

by learningcode_x1mckf
March 8, 2023
0
Beginner’s guide to server-side Swift using the Hummingbird framework

Swift on the Server in 2023 Three years in the past I began to focus on Vapor, the preferred web-framework written in Swift, which served me very...

Read more

What’s new in Swift 5.8 – Hacking with Swift

by learningcode_x1mckf
March 8, 2023
0
What’s new in Swift 5.8 – Hacking with Swift

Though many main Swift modifications are at present percolating by way of Swift Evolution, Swift 5.8 itself is extra of a clear up launch: there are additions, sure,...

Read more

Customizing SwiftUI Bottom Sheet’s Background and Scrolling

by learningcode_x1mckf
February 28, 2023
0
Customizing SwiftUI Bottom Sheet’s Background and Scrolling

For the reason that launch of iOS 16, it’s straightforward to create an interactive backside sheet utilizing SwiftUI. All it is advisable to do is to embed a...

Read more
Next Post
Get Lifetime Access to This 60-Hour Java Programming Training Bundle @ 97% Discount

Get Lifetime Access to This 60-Hour Java Programming Training Bundle @ 97% Discount

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

Cloud Java Developer (Senior) (0257)

Cloud Java Developer (Senior) (0257)

January 5, 2023
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

LLVM 16.0 Released With New Intel/AMD CPU Support, More C++ … – Phoronix

March 18, 2023
Strait Up: From Java to Borneo, and everything in between🛻

Strait Up: From Java to Borneo, and everything in between🛻

January 13, 2023

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • Introducing Carbon, Google's Experimental Successor for C++ – MUO – MakeUseOf
  • Oracle aims to sustain Java's 27-year franchise with version 20 rollout – SiliconANGLE News
  • How to learn JavaScript? – JavaScript – SitePoint

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?