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 aid to do away with CocoaPods (you might need observed that I am not an enormous fan). In an effort to begin the entire process, you simply need to run pod deintegrate in your undertaking folder.



Yep, no traces left, however nonetheless, in case 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 in case you want an inventory of your third-party libraries, you’ll be able to hold your Podfile round for some time, so you’ll be able to make sure that you’ve migrated every little thing. Other than these information, CocoaPods is now gone. Get pleasure from! 👍

Utilizing Swift Packages in Xcode 11

Many standard 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 it’s essential to do now could be to enter a legitimate Swift Package deal repository URL that you simply’d like to make use of: normally you’ll be able to copy & paste the github URL out of your browser. Legitimate signifies that the git repo has to comprise a Package deal.swift file.

You may as well 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 unsure 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 suitable facet. The factor that you simply want is beneath the supply key. 😉


You may choose the required model quantity, department and even commit message that you simply’d like to make use of throughout the checkout course of. This is available in extraordinarily useful if you’re 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 undertaking and another construct configuration adjustments…


Now you might be able to import your framework in your goal. Properly carried out. 👏


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…


Title your library first, then reserve it someplace in your disk. Xcode will create virtually every little thing for you that’s required to make use of a Swift bundle 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 undertaking.

An important factor is that it’s a must to 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 be taught 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 it’s essential 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 in regards to the anatomy of Swift Package deal Supervisor you’ll be able to examine all of the bundle associated evolution proposals right here. These proposals are normally very well documented. 📖

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


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 (do not forget to make use of git tags).

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments