Cocoapods: pod trunk push fails on Swift 4.2 with backwards incompatible changes

Created on 20 Sep 2018  ·  10Comments  ·  Source: CocoaPods/CocoaPods

Report

What did you do?

  1. Download https://github.com/plivesey/consistencymanager-ios
  2. pod trunk push ConsistencyManager.podspec
  3. NOTE: you can reproduce the same issue by running pod lib lint

What did you expect to happen?

I expected it to publish the library with no problem.

What happened instead?

- ERROR | xcodebuild:  /Users/peterlivesey/Repo/ConsistencyManager-iOS/ConsistencyManager/ConsistencyManager.swift:839:161: error: 'didReceiveMemoryWarningNotification' has been renamed to 'NSNotification.Name.UIApplicationDidReceiveMemoryWarning'
- NOTE  | xcodebuild:  UIKit.UIApplication:36:22: note: 'didReceiveMemoryWarningNotification' was introduced in Swift 4.2

CocoaPods Environment

Stack

   CocoaPods : 1.6.0.beta.1
        Ruby : ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17]
    RubyGems : 2.5.2.3
        Host : Mac OS X 10.13.6 (17G65)
       Xcode : 10.0 (10A255)
         Git : git version 2.17.1 (Apple Git-112)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 1d3f97ee611fd56a72e31686205184a6e03a1f45

Installation Source

Executable Path: /usr/local/bin/pod

Plugins

cocoapods-deintegrate : 1.0.2
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.3.1
cocoapods-try         : 1.1.0

Project that demonstrates the issue

https://github.com/plivesey/consistencymanager-ios

Most helpful comment

You should migrate the podspec if its yours to use s.swift_version = '4.0' instead of the .swift-version file.

All 10 comments

It looks like the project that's used for pod lib lint and pod trunk push uses swift 4.0? I couldn't verify this though because the project used in the /var/private directory seems to be deleted after I run these commands, so I could be mistaken here.

I think this issue would happen for any project with backwards incompatible APIs in Swift 4.2, but I'm surprised that this hasn't been reported yet (as far as I could find).

@plivesey you can use the --no-clean option when running pod lib lint to inspect the temporary workspace

Hmmm...the project seems to specify Swift 3, so I don't think that's actually the problem. Also, the build actually succeeds. It fails on:

    ** BUILD SUCCEEDED **

   Testing with `xcodebuild`.
 -> ConsistencyManager (7.0.0)
    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.

I'm not sure what command is run here, so don't know how to test. If I run tests from the workspace, nothing happens.

@plivesey make sure you switch the scheme to 'Release' configuration once you open the workspace.

The build succeeded on macOS but failed on iOS:

    /Users/dimitris/Development/ios/consistencymanager-ios/ConsistencyManager/ConsistencyManager.swift:839:161: error: 'didReceiveMemoryWarningNotification' has been renamed to 'NSNotification.Name.UIApplicationDidReceiveMemoryWarning'
                NotificationCenter.default.addObserver(self, selector: #selector(UIApplicationDelegate.applicationDidReceiveMemoryWarning(_:)), name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
                                                                                                                                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                                                                                                                    NSNotification.Name.UIApplicationDidReceiveMemoryWarning
    UIKit.UIApplication:36:22: note: 'didReceiveMemoryWarningNotification' was introduced in Swift 4.2
        public class let didReceiveMemoryWarningNotification: NSNotification.Name
                         ^

Please contact the author to fix the issue and their code to work with Xcode 10.

Thanks, @dnkoutso. I've got more information on the bug (and I still think this is a cocoapods bug).

The code does work on Xcode 10, but it only works on Swift 4.2 (not swift 3). It looks like pod lib lint runs the code on Swift 3. Here's what I reproduced:

$ pod lib lint --no-clean
open /var/folders/......../App.xcworkspace
Change the scheme to release
Build
It failed (expected)
Change language in Project Settings to Swift 4.2
Build
It succeeds

So, I think I need to force cocoapods to use Swift 4.2 for linting. I don't know how to specify that though? Is that even possible?

(And can you reopen the ticket if you agree that this isn't a problem with my code? 🙏 )

It uses Swift 3.0 because the there is a .swift-version file in the repo that says to use 3.0

We can continue discussion here even if its closed. I will re-open once we verify 100% its a CocoaPods library issue. So far it does not appear to be.

You should migrate the podspec if its yours to use s.swift_version = '4.0' instead of the .swift-version file.

ah yes! Thank you. I was missed that file.

Thanks for the help.

Was this page helpful?
0 / 5 - 0 ratings