How to mark an imported Cocoapod framework deprecated

Viewed 327

In one of our frameworks we're using the SwiftObserver pod. Our framework is used in several other frameworks of our app.

After raising the development target to iOS 13.0 I'd like to mark all usage of the SwiftObserver methods as deprecated to gradually change our codebase to use Combine's observers.

I was thinking of forking SwiftObserver or linking a local copy of the pod from now on. However parts of the app that still use SwiftObserver should be able to continue updating it using pod update as long as not all code has been changed to use Combine.

Is there a simpler way, maybe in the podfile, or with some sort of overwrite, to mark the usage of that pod deprecated without breaking any of its funktionality?

Please let me know if you have further questions or if there are any code samples I can provide.

2 Answers

An alternative to using swiftlint proposed by @SoumyaMahunt, could be to setup your own private repo.

Here's how you might be able to achieve what you want:

  1. Create a private spec repo to be used to resolve the CocoaPod dependencies.
  2. Create a podspec for SwiftObserver and set it to deprecated -> s.deprecated = true
  3. Add the private spec repo above source 'https://github.com/CocoaPods/Specs.git', this is important to force CocoaPods to resolve against your private repo before searching in the global default repo.

Pros

  • You can use this private spec repo for other private pods
  • You can deprecate other pods without having to hack in your project.

Cons

  • Can be tideous to manually make sure the third-party pods are updated to the latest versions (you'll have to manually add new podspecs for the updated version).
Helpful links:

https://guides.cocoapods.org/making/private-cocoapods.html

https://guides.cocoapods.org/syntax/podspec.html#deprecated

If you are using swiftlint, you can add custom rule to produce warning with a message indicating deprecation. You can also adjust severity of these warning to cause compilation error as well.

For producing warning with SwiftObserver pod create the following custom rule in swift lint config file (.swiftlint.yml):

custom_rules:
  pod_deprecation:
    name: "Deprecated POD use"
    regex: "(SwiftObserver)"
    match_kinds:
      - identifier
    message: "Use of deprecated pods"

This rule will cause warning with the message provided in the message parameter for all the files that import SwiftObserver:

sample warning

Related