Search code examples
iosswiftxcodecocoapodsmqtt

Do I still need CocoaPod installation?


I am new to XCode and Swift. Trying to create a simple project that uses MQTT protocol. For that, there is a Swift library CocoaMQTT and there are directions on how to integrate it in an XCode project:

Installation
To integrate CocoaMQTT into your Xcode project using CocoaPods,
you need to modify you Podfile like the followings:

use_frameworks!
target 'Example' do
pod 'CocoaMQTT' end

Then, run the following command:
$ pod install

At last, import "CocoaMQTT" to your project:
import CocoaMQTT

The directives above are not straight forward to me as for a newbie, and I followed another way by importing the CocoaMQTT package through the XCode main menu: File -> Add Packages. Once the package was downloaded, I saw that the package (and the other dependencies) were automatically added to my project in the file navigator:

enter image description here

Question: do I still need to do CocoaPad installation as described above, or importing the package as I did is the new and sufficient way to integrate the library into the project? The Podfile that is mentioned in the instructions cannot be modified in XCode.


Solution

  • [Swift package] is the new and sufficient way

    Correct. The library is now installed in your project and there is no further work to do.

    In general, Swift packages supersede Cocoapods. Wherever possible, if a library offers a Swift package installation, you'll probably want to use that rather than Cocoapods.

    In this particular case, you should file an issue on the documentation. They have added Swift Package as an alternative way of installing this library but they have forgotten to add that information to the instructions in the Readme.