Search code examples
swiftxcodecocoapods

Is it ok to use a lower swift version on a cocoapod when the project is built in a higher swift version?


I need to upgrade a project to run on swift 5 yet, the last time someone upgraded the project it was built on swift 4. So I completed the Xcode project update yet when I try and compile, some of my cocoa pods are saying they are using swift 5 but the pod themselves are not built for 5 yet. Which is causing compile errors.

So what I think I need to do is go through each pod build menu and manually set the swift version to be the last swift version that pod was built on. Is this the correct way to fix this issue? Am I going to have any repercussions from doing this?

P.S. I found out it is ok to do this. Yet one of my pods is supposed to be built in swift 3 because it says one that one of the lines of code has been deprecated in swift 4. Ill update this when i figure out what to do in that situation but if one of you gurus wanna take the lead on this one that be great.


Solution

  • So yes the correct way to fix this issue is to go to each pod that can only run on a lower version of swift and manually change the swift version in the build menu. The issue i was having was when i ran the auto update code to swift 5 was that Xcode also changed all the pods to become swift 5. Since those pods could not run on Swift 5 just as of yet it caused build errors.

    Also regarding my P.S. note the reason why that happened was because one of the pods commands needed to be changed to the one they updated in the installation options.

    Hope this helps anyone else who would come across this issue.

    EDIT: To be even more precise with what is going on is the fact that every time I run pod install there are a few pods that get reset back to swift 5 when it should be run in swift 4. This is because the authors of the pods have not set the swift_version parameter to be the swift version the pod should be using. This causes the app to not be able to compile with build-time errors.

    to fix this add this code to your Podfile and it will manually set the swift version everytime. Just remember to remove it for each pod once they are updated cause you will overwrite the creators pod swift version (if they ever think of adding it)

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        if target.name == 'KMPlaceholderTextView' || target.name == 'TagWriteView' || target.name == 'UILoadControl'
          target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '4.0'
          end
        end
      end
    end