Friday, November 6, 2026
HomeiOS DevelopmentMigrating from CocoaPods to Swift Package deal Supervisor

Migrating from CocoaPods to Swift Package deal Supervisor

[ad_1]

Fully eradicating CocoaPods

Taking step one is at all times the toughest, however this time it is fairly a reduction to eliminate CocoaPods (you might need observed 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, should 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. Possibly should you want an inventory of your third-party libraries, you’ll be able to preserve your Podfile round for some time, so you’ll be able to make certain that you’ve migrated all the pieces. Other than these recordsdata, CocoaPods is now gone. Take pleasure in! 👍

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 package deal first, then I will information you thru making your personal Swift package deal that may 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 essential do now’s to enter a legitimate Swift Package deal repository URL that you simply’d like to make use of: often 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 may as well reset, resolve or replace your packages underneath the Swift Packages menu merchandise. It is actually good to have all the pieces in a single place.

If you’re undecided the place to search 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 appropriate aspect. The factor that you simply want is underneath the supply key. 😉


You may choose the required model quantity, department and even commit message that you simply’d like to make use of through the checkout course of. This is available in extraordinarily helpful if you’re utilizing some older model of a particular framework or library.


A Swift package deal 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’re able to import your framework in your goal. Effectively carried out. 👏


How you can create a Swift Package deal for iOS?

The reply is sort 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 virtually all the pieces for you that’s required to make use of a Swift package deal on Apple platforms.

Nonetheless, it’s a must to add just a few 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 challenge.

Crucial factor is that it’s a must 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 identify parameter. You may study extra in regards to the manifest format change from this Swift evolution proposal.



import PackageDescription

let package deal = 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 it’s essential configure a construct settings or hyperlink a particular dependency. I am not going into particulars, as a result of this might 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 test 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 git@github.com:<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).

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments