Swift Version NativeScript

前端 未结 5 765
醉梦人生
醉梦人生 2020-12-30 16:27

Using NativeScript how can I run a project under iOS? I get these messages when I run tns run iOS --bundle

Webpack compilation complete. Watchin         


        
相关标签:
5条回答
  • 2020-12-30 16:52

    The problem is with Cocoapods 1.6.x which have different behavior when it comes up to SWIFT_VERSION. Previously it was possible to set the SWIFT_VERSION in post_install hook of the Podfile, but now the pod install command fails before even getting to post_install. The best solution is to use Cocoapod which already has SWIFT_VERSION set, i.e. in case you face the error, try to contact the Pod author. Meanwhile, as a workaround, you can add a pre_install script in your <path to App_Resources/iOS/Podfile file with the following content:

    pre_install do |installer|
        installer.analysis_result.specifications.each do |s|
            if s.name == 'Socket.IO-Client-Swift' || s.name == 'Starscream' || s.name == 'StarscreamSocketIO' || s.name == 'Toaster'
                s.swift_version = '4.2'
            end
        end
    end
    

    For each of the Pods you can set different Swift version based on their requirements.

    0 讨论(0)
  • 2020-12-30 16:52

    Here is the real fix ! You can't stick with Cocoapods 1.5.3 forever...

    Downgrading to 1.5.3 isn't a proper workaround and will not be sustainable in the future. In fact, this error is due to a new behavior introduced in Cocoapods 1.6.0 version, which force developers to set a Swift version to their projects. The goal is in fact to make library developers specify a Swift version in their podspec, so that library users don't have to do this manually (thanks to post_install scripts for example). You can see my discussion about this with a Cocoapods maintainer here. I do agree that this behavior is a bit misleading, as we try to set the Swift version in post_install script but an error is returned before…

    In fact, as I have been told by the maintainer, the correct fix to this issue is to set a Swift version at project level (and therefore not at Pod level). To do this, just add a new User Defined Setting in Build Settings, with key SWIFT_VERSION and value 4.0 (for example, as whatever value should work here if you also set the version at Pod level with post_install script).

    Long story short, the fix is to add this key/value :

    Note that as you're using NativeScript, you may want to set the Swift version by running command export SWIFT_VERSION=4 in your project folder, before building.

    0 讨论(0)
  • 2020-12-30 16:54

    I have it fixed with @K Brown's answer.

    Was having these errors when running tns run ios --bundle for Socket.IO-Client-Swift, StarscreamSocketIO and Toaster when both v1.6.0 and v1.5.3 of Cocoapods installed:

    - `<package name>` does not specify a Swift version and none of the targets 
    (`<project name>`) integrating it have the `SWIFT_VERSION` attribute set. 
    Please contact the author or set the `SWIFT_VERSION` attribute in at least one 
    of the targets that integrate this pod. 
    

    Below are the commands used:

    sudo gem uninstall cocoapods

    sudo gem install cocoapods -v 1.5.3

    rm -Rf platforms

    tns install

    tns run ios --bundle

    0 讨论(0)
  • 2020-12-30 17:06

    Just had these same errors and found out downgrading from cocoapods 1.6.0 to 1.5.3 fixed it for me.

        sudo gem uninstall cocoapods
        sudo gem install cocoapods -v 1.5.3
    
    0 讨论(0)
  • 2020-12-30 17:07

    The problem here seems to be Toaster (2.0.4), which appears to have been developed for Swift 3.

    I did this in order to resolve the issue:

    1. go to the main folder for the nativescript project

    2. In your bash shell, do:

      % export SWIFT_VERSION=3

    3. Then do your usual:

      % tns build ios --bundle

    4. Then open the project in Xcode:

      % cd platforms/ios

      % Open *.workspace

    You'll get a warning about a build error in the pods project and may need to set your development team, but it should work.

    0 讨论(0)
提交回复
热议问题