Tuesday, February 7, 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 create a Swift package collection?

learningcode_x1mckf by learningcode_x1mckf
September 12, 2022
in Swift
0
How to create a Swift package collection?
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


2022/01/20

On this tutorial I will present you learn how to create your individual bundle assortment out of your favourite Swift libraries.

Swift

What’s a Swift bundle assortment?


A Swift package collection is a curated record of packages. Swift Package deal Supervisor customers can subscribe to those collections, this fashion they’re going to have the ability to search libraries and uncover new ones. A set just isn’t equal with a bundle index or registry service, however normally means a smaller (one way or the other associated) group of Swift packages.


For instance should you check out the Swift Package Index web site, it is all about discovering new Swift packages, however every creator can have its personal assortment, so if we go to the Vapor web page, there you’ll be able to see the URL of the Swift bundle assortment hyperlink. This assortment solely accommodates these packages which are authored by Vapor. It is only a small, curated subset of the whole content material of the Swift Package deal Index web site.


So we will say {that a} bundle registry service is concentrated on internet hosting and serving bundle sources, a bundle index service is all about discovering and looking out packages and a bundle assortment is normally a smaller curated record that may be simply shared with others. It may be a listing of your most well-liked Swift dependencies that your organization makes use of for constructing new tasks. 💡




Getting ready the atmosphere


In an effort to create a bundle assortment, you will have to put in a instrument known as Swift package collection generator. It was created by Apple and it was launched on this WWDC session in 2021.


You may set up the bundle assortment generator by operating these instructions:


git clone https://github.com/apple/swift-package-collection-generator
cd swift-package-collection-generator 
swift construct --configuration launch

sudo set up .construct/launch/package-collection-generate /usr/native/bin/package-collection-generate
sudo set up .construct/launch/package-collection-diff /usr/native/bin/package-collection-diff
sudo set up .construct/launch/package-collection-sign /usr/native/bin/package-collection-sign
sudo set up .construct/launch/package-collection-validate /usr/native/bin/package-collection-validate


You may additionally want a certificates and a key with a view to signal a bundle assortment. Signing packages should not required, however it is suggested. The signature might be added with the package-collection-sign command, however to begin with you will want a developer certificates from the Apple developer portal. 🔨


Earlier than you go to the dev portal, merely launch the Keychain Entry app and use the Keychain Entry > Certificates Assitant > Request a Certificates from a Certificates Authority menu merchandise to generate a brand new CertificateSigningRequest.certSigningRequest file. Double test your electronic mail handle and choose the Saved to disk choice and press the Proceed button to generate the file.


Now you should use the CSR file to generate a brand new certificates utilizing the Apple dev portal. Press the plus icon subsequent to the Certificates textual content and scroll right down to the Companies part, there it’s best to see a Swift Package deal Assortment Certificates choice, choose that one and press the Proceed button. Add your CSR file and press Proceed once more, now it’s best to have the ability to obtain the certificates that can be utilized to correctly signal your Swift bundle collections. 🖊


We nonetheless need to export the non-public key that is behind the certificates and we additionally need to convert it to the best format earlier than we will begin coping with the contents of the bundle assortment itself. Double click on the downloaded certificates file, this can add it to your keychain. Discover the certificates (click on My Certificates on the highest), proper click on on it and select the Export menu merchandise, save the Certificates.p12 file someplace in your disk. Remember so as to add password safety to the exported file, in any other case the important thing extraction will not work.


Now we should always use the openssl to extract the non-public key from the p12 file utilizing an RSA format.


openssl pkcs12 -nocerts -in Certificates.p12 -out key.pem && openssl rsa -in key.pem -out rsa_key.pem



Run the command and enter the password that you’ve got used to export the p12 file. This command ought to extract the required key utilizing the correct format for the bundle assortment signal command. You may want each the downloaded certificates and the RSA key file throughout the bundle creation. 📦




Constructing a Swift bundle assortment


It’s time to create a model new Swift bundle assortment. I will construct one for my Swift repositories situated beneath the Binary Birds group. The whole lot begins with a JSON file.



    "identify": "Binary Birds packages",
    "overview": "This assortment accommodates the our favourite Swift packages.",
    "creator": 
        "identify": "Tibor Bödecs"
    ,
    "key phrases": [
        "favorite"
    ],
    "packages": [
        
            "url": "https://github.com/binarybirds/swift-html"
        ,
        
            "url": "https://github.com/BinaryBirds/liquid"
        ,
        
            "url": "https://github.com/BinaryBirds/liquid-kit"
        ,
        
            "url": "https://github.com/BinaryBirds/liquid-local-driver"
        ,
        
            "url": "https://github.com/BinaryBirds/liquid-aws-s3-driver"
        ,
        
            "url": "https://github.com/BinaryBirds/spec"
        
    ]


You may learn extra in regards to the Package Collection format file on GitHub, however if you wish to stick to the fundamentals, it’s just about self-explanatory. You may give a reputation and a brief overview description to your assortment, set the creator, add some associated key phrases to enhance the search expertise and at last outline the included packages through URLs.


Save this file utilizing the enter.json identify. For those who run the generate command with this enter file it will attempt to fetch the repositories listed contained in the JSON file. In an effort to get extra metadata details about the GitHub repositories you too can present an -auth-token parameter together with your private entry token, you’ll be able to learn extra in regards to the accessible choices by operating the command with the -h or --help flag (package-collection-generate -h).


package-collection-generate enter.json ./output.json


The generated output file will include the required bundle assortment metadata, however we nonetheless need to signal the output file if we need to correctly use it as a group file. In fact the signal step is elective, however it’s suggest to work with signed collections. 😇



package-collection-sign output.json assortment.json rsa_key.pem swift_package.cer


Lastly it’s best to add your assortment.json file to a public internet hosting service. For instance I’ve created a easy SPM repository beneath my group and I can use the raw file URL of the gathering JSON file to make use of it with SPM or Xcode.


For those who desire the command line you have got a number of choices to control Swift Package deal Collections. For more information you’ll be able to learn the associated Swift Package Manager documentation, however listed below are some instance instructions that you should use so as to add, record, refresh search or take away a group:

swift package-collection record
swift package-collection add https://uncooked.githubusercontent.com/BinaryBirds/SPM/most important/assortment.json
swift package-collection refresh
swift package-collection search --keywords html

swift package-collection take away https://uncooked.githubusercontent.com/BinaryBirds/SPM/most important/assortment.json


If you’re growing apps utilizing Xcode, you should use the Package deal Dependencies menu beneath your undertaking settings to handle your bundle dependencies and use bundle collections.



Swift Package deal Collections are nice if you wish to set up your Swift libraries and also you need to share them with others. If you’re a heavy Xcode person you will get pleasure from utilizing collections for certain. ☺️








Source link

You might also like

The abstract Vapor service factory design pattern

SwiftNIO tutorial – The echo server

Introducing – Vapor cheatsheet – The.Swift.Dev.

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

The abstract Vapor service factory design pattern

by learningcode_x1mckf
February 1, 2023
0
The abstract Vapor service factory design pattern

I've written a number of articles about manufacturing unit design patterns on my weblog and this time I might like to speak a couple of particular one, which...

Read more

SwiftNIO tutorial – The echo server

by learningcode_x1mckf
January 27, 2023
0
SwiftNIO tutorial – The echo server

Intoducing SwiftNIO In the event you used a excessive degree net framework, corresponding to Vapor, up to now, you would possibly had some interplay with occasion loops...

Read more

Introducing – Vapor cheatsheet – The.Swift.Dev.

by learningcode_x1mckf
January 23, 2023
0
Introducing – Vapor cheatsheet – The.Swift.Dev.

Out there on Gumroad Thanks for supporting my work by buying the cheatsheet. 🙏 Download now A whole Vapor framework reference for novices. greater than...

Read more

iCloud Programming Tutorial for iOS: An Introduction

by learningcode_x1mckf
January 18, 2023
0
iCloud Programming Tutorial for iOS: An Introduction

Editor’s observe: This week, we work with Ziad Tamim once more to provide you an introduction of iCloud programming. You’ll learn to save and retrieve knowledge from iCloud.On...

Read more

Easy multipart file upload for Swift

by learningcode_x1mckf
January 18, 2023
0
Easy multipart file upload for Swift

I imagine that you've got already heard in regards to the well-known multipart-data add method that everybody likes to add recordsdata and submit type knowledge, but when not,...

Read more
Next Post
Senior Java Analyst Programmer at Ntice Search

Senior Java Analyst Programmer at Ntice Search - Western Cape Cape Town

Leave a Reply Cancel reply

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

Related News

Google Explains More About Head Section & JavaScript

Google Explains More About Head Section & JavaScript

January 16, 2023
JavaScript Web Frameworks Software (COVID-19) to Witness Astonishing Growth by Forecast 2022-2031

JavaScript Web Frameworks Software (COVID-19) to Witness Astonishing Growth by Forecast 2022-2031

November 24, 2022
Review: Visual Studio Code shines for Java

JDK 20: The new features in Java 20

November 24, 2022

Browse by Category

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

RECENT POSTS

  • C++ Is TIOBE's Language Of The Year – iProgrammer
  • JobRunr, the Java Scheduler Library, Released Version 6.0 – InfoQ.com
  • An Introduction to Lodash and Its Benefits for JavaScript Developers – MUO – MakeUseOf

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?