Sunday, September 25, 2022
HomeiOS DevelopmentMigrating from CocoaPods to Swift Package deal Supervisor

Migrating from CocoaPods to Swift Package deal Supervisor


Fully eradicating CocoaPods

Taking step one is at all times the toughest, however this time it is fairly a reduction to eliminate CocoaPods (you may need seen that I am not an enormous fan). As a way to begin the entire process, you simply must run pod deintegrate in your challenge folder.



Yep, no traces left, however nonetheless, if you happen to go to the folder you may discover some remaining trash just like the .xcworkspace file, the Podfile and the Podfile.lock. Merely delete these, since you will not want them anymore. Perhaps if you happen to want a listing of your third-party libraries, you’ll be able to hold your Podfile round for some time, so you’ll be able to ensure that you’ve migrated every little thing. Aside from these recordsdata, CocoaPods is now gone. Get pleasure from! 👍

Utilizing Swift Packages in Xcode 11

Many in style frameworks already assist SPM. For instance, Alamofire is able to use on iOS, macOS, tvOS, watchOS through the built-in Swift Package deal Supervisor. Let me present you how you can combine an present bundle first, then I will information you thru making your personal Swift bundle that may work on appleOS targets.

Triggering the circulate is a bit of cake. Simply go to the File menu and choose Swift Packages, lastly click on on the Add Package deal Dependency… menu merchandise.


The one factor you’ll want to do now’s to enter a sound Swift Package deal repository URL that you just’d like to make use of: normally you’ll be able to copy & paste the github URL out of your browser. Legitimate implies that the git repo has to comprise a Package deal.swift file.

You too can reset, resolve or replace your packages beneath the Swift Packages menu merchandise. It is actually good to have every little thing in a single place.

If you’re undecided the place to seek out the git repository URL, you’ll be able to go to cocoapods.org, enter your pod identify and click on on the See Podspec menu merchandise on the proper facet. The factor that you just want is beneath the supply key. 😉


You may choose the required model quantity, department and even commit message that you just’d like to make use of in the course of the checkout course of. This is available in extraordinarily useful in case you are utilizing some older model of a selected framework or library.


A Swift bundle can comprise a number of merchandise (a product is a framework or an executable), you’ll be able to choose and combine them individually in Xcode.


Lastly Xcode will do the required integration course of, like embedding the library into the challenge and another construct configuration adjustments…


Now you might be able to import your framework in your goal. Nicely completed. 👏


Methods to create a Swift Package deal for iOS?

The reply is kind of easy. Simply use Xcode’s File menu and choose: New > Swift Package deal…


Identify your library first, then reserve it someplace in your disk. Xcode will create nearly every little thing for you that’s required to make use of a Swift bundle on Apple platforms.

Nonetheless, you must add a number of issues to the Package deal.swift file, as a result of by default these Swift packages will not work in case you are planning to combine them with an iOS challenge.

A very powerful factor is that you must configure your bundle to run on particular platforms. You are able to do this by including a brand new platforms part contained in the Package deal description object, proper after the identify parameter. You may study extra in regards to the manifest format change from this Swift evolution proposal.



import PackageDescription

let bundle = Package deal(
    identify: "MyLibrary",
    platforms: [
        .iOS(.v12),
    ],
    merchandise: [
        .library(
            name: "MyLibrary",
            targets: ["MyLibrary"]),
    ],
    dependencies: [
        
    ],
    targets: [
        .target(
            name: "MyLibrary",
            dependencies: []),
        .testTarget(
            identify: "MyLibraryTests",
            dependencies: ["MyLibrary"]),
    ]
)


Oh, by the way in which SPM now helps goal particular construct settings if you’ll want to configure a construct settings or hyperlink a selected dependency. I am not going into particulars, as a result of this could possibly be a standalone tutorial, however if you wish to study extra in regards to the anatomy of Swift Package deal Supervisor you’ll be able to verify all of the bundle associated evolution proposals right here. These proposals are normally rather well documented. 📖

As a final step you solely want a git repository populated with the supply recordsdata.


git init
git add .
git commit -m "preliminary"
git distant add origin [email protected]:<your-user>/MyLibrary.git
git push -u origin grasp
git tag 1.0.0
git push --tags


Now you’ll be able to add your library as I described it earlier than (remember to make use of git tags).

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular