Migrating from CocoaPods to Swift Package deal Supervisor

[ad_1]

Utterly 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 a giant fan). With a purpose to begin the entire process, you simply should run pod deintegrate in your challenge folder.



Yep, no traces left, however nonetheless, when you go to the folder you will 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 when you want an inventory of your third-party libraries, you may maintain your Podfile round for some time, so you may make sure that you’ve migrated every 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 by way of the built-in Swift Package deal Supervisor. Let me present you easy methods to combine an present bundle first, then I am going to information you thru making your individual Swift bundle 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 is advisable do now could be to enter a legitimate Swift Package deal repository URL that you simply’d like to make use of: normally you may 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 also reset, resolve or replace your packages underneath the Swift Packages menu merchandise. It is actually good to have every thing in a single place.

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


You’ll be able to 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 helpful in case you are utilizing some older model of a particular framework or library.


A Swift bundle 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 challenge and another construct configuration adjustments…


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


Tips on 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 reserve it someplace in your disk. Xcode will create nearly every 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.

Crucial 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 title parameter. You’ll be able to study extra in regards to the manifest format change from this Swift evolution proposal.



import PackageDescription

let bundle = 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 is advisable configure a construct settings or hyperlink a particular 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 may 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 may add your library as I described it earlier than (remember to make use of git tags).

[ad_2]

Leave a Reply