Sunday, October 15, 2023
HomeiOS DevelopmentMigrating from CocoaPods to Swift Package deal Supervisor

Migrating from CocoaPods to Swift Package deal Supervisor


Utterly eradicating CocoaPods

Taking step one is all the time the toughest, however this time it is fairly a reduction to eliminate CocoaPods (you might need seen that I am not a giant fan). With the intention to begin the entire process, you simply must run pod deintegrate in your venture folder.



Yep, no traces left, however nonetheless, in the event you 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 in the event you want a listing of your third-party libraries, you may hold your Podfile round for some time, so you may ensure that you’ve migrated every part. Aside from these recordsdata, CocoaPods is now gone. Get pleasure from! 👍

Utilizing Swift Packages in Xcode 11

Many well-liked 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 the best way to combine an present package deal first, then I am going to information you thru making your individual Swift package deal that can work on appleOS targets.

Triggering the circulate is a chunk 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 it’s worthwhile to do now’s to enter a sound Swift Package deal repository URL that you just’d like to make use of: often you may copy & paste the github URL out of your browser. Legitimate implies that the git repo has to comprise a Package deal.swift file.

You may as well reset, resolve or replace your packages below the Swift Packages menu merchandise. It is actually good to have every part in a single place.

If you’re unsure the place to search out the git repository URL, you may go to cocoapods.org, enter your pod title and click on on the See Podspec menu merchandise on the best aspect. The factor that you just want is below the supply key. 😉


You possibly can 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 helpful if you’re utilizing some older model of a selected framework or library.


A Swift package deal can comprise a number of merchandise (a product is a framework or an executable), you may choose and combine them individually in Xcode.


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


Now you’re able to import your framework in your goal. Properly performed. 👏


Find out how 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…


Title your library first, then put it aside someplace in your disk. Xcode will create nearly every part for you that’s required to make use of a Swift package deal on Apple platforms.

Nonetheless, it’s important to add a couple of issues to the Package deal.swift file, as a result of by default these Swift packages will not work if you’re planning to combine them with an iOS venture.

An important factor is that it’s important to configure your package deal 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 title parameter. You possibly can be taught extra concerning the manifest format change from this Swift evolution proposal.



import PackageDescription

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


Oh, by the way in which SPM now helps goal particular construct settings if it’s worthwhile to configure a construct settings or hyperlink a selected dependency. I am not going into particulars, as a result of this might be a standalone tutorial, however if you wish to be taught extra concerning the anatomy of Swift Package deal Supervisor you may verify all of the package deal associated evolution proposals right here. These proposals are often very 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 may add your library as I described it earlier than (remember to make use of git tags).



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments