在pod安装后,Alamofire会出现错误

时间:2023-01-18 00:25:29

I know that there is many questions about that but I can't find a solution for that. I use Xcode 8 and swift 2.3. When I add Alamofire in my application the build always fails and it gives me error in relation with the swift version. If anyone was facing the same issue and fixed it please give me the solution for than or advice me about the right way to use Alamofire without errors (it's the first time that I will use it and I'm really new to ios devlopement)

我知道有很多问题,但我找不到解决的办法。我使用Xcode 8和swift 2.3。当我在我的应用程序中添加Alamofire时,构建总是失败,它会给我与swift版本之间的错误。如果有人遇到同样的问题并修复了它请给我解决方案或者建议我如何正确使用Alamofire而不出错(这是我第一次使用它,我对ios devlopement非常陌生)

Edit: I tested this: pod 'Alamofire', '~> 3.5' then I did a pod install and when I build the project I got this error:

编辑:我测试了这个:pod 'Alamofire' ~> 3.5'然后我做了pod安装,当我构建项目时,我得到了这个错误:

Alamofire will not be code signed because its settings don't specify a development team. “Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

Alamofire将不会被代码签名,因为它的设置没有指定开发团队。“使用遗留的Swift语言版本”(SWIFT_VERSION)被要求正确配置为使用Swift的目标。使用[编辑>转换>到当前的Swift语法…]菜单选择一个Swift版本或使用Build Settings编辑器直接配置构建设置。

2 个解决方案

#1


1  

In your podfile specify that you wan to download the 2.3 version by pasting this at the end of you Pofile under everything else in there.

在您的podfile中指定您要下载2.3版本,您可以在文件的末尾将其粘贴到您的Pofile中。

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
           config.build_settings['SWIFT_VERSION'] = '2.3'
        end
   end
end

In the middle line you can see that the SWIFT_VERSION for the build settings is changed to be 2.3 specifically. Overall this is how your podfile should look like:

在中间的一行中,您可以看到,用于构建设置的SWIFT_VERSION被特别更改为2.3。总的来说,你的播客应该是这样的:

target 'YourApp' do
  use_frameworks!

  # Pods for Weatherly
  pod 'Alamofire'

end

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
           config.build_settings['SWIFT_VERSION'] = '2.3'
        end
   end
end

Hope this helped :)

希望这有助于:)

#2


0  

It looks like you're not really using Swift 2.3.

看起来你并没有使用Swift 2.3。

  1. Go to Build Settings section of your target's settings.
  2. 去建立你的目标设置的设置部分。
  3. Search for Use Legacy Swift Language Version and set it to YES if you really want to use Swift 2.3
  4. 搜索使用遗留的Swift语言版本,如果您真的想使用Swift 2.3,请将其设置为YES
  5. Clean and build.
  6. 清洁和构建。

If that doesn't help, try the following:

如果这没有帮助,试试下面的方法:

  1. Open project.pbxproj file
  2. 开放的项目。pbxproj文件

You can find it in the *.xcodeproj: Right click -> Show package contents -> project.pbxproj)

你可以在*中找到它。xcodeproj:右键单击->显示包内容-> project.pbxproj)

  1. Search for SWIFT_VERSION. If there is any other value except 2.3, set it manually. For example SWIFT_VERSION = 3.0; -> SWIFT_VERSION = 2.3;
  2. 寻找SWIFT_VERSION。如果除了2.3之外还有其他值,请手动设置。例如SWIFT_VERSION = 3.0;- > SWIFT_VERSION = 2.3;
  3. Clean and build again.
  4. 清洁并再次构建。

The reason for manual editing of project.pbxproj file is that sometimes Xcode doesn't update all values for SWIFT_VERSION key. Faced this issue on 8.0, perhaps it was already fixed in 8.1

项目手工编辑的原因。pbxproj文件是有时Xcode不会更新SWIFT_VERSION键的所有值。在8.0的问题上,也许它已经固定在8.1了。

#1


1  

In your podfile specify that you wan to download the 2.3 version by pasting this at the end of you Pofile under everything else in there.

在您的podfile中指定您要下载2.3版本,您可以在文件的末尾将其粘贴到您的Pofile中。

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
           config.build_settings['SWIFT_VERSION'] = '2.3'
        end
   end
end

In the middle line you can see that the SWIFT_VERSION for the build settings is changed to be 2.3 specifically. Overall this is how your podfile should look like:

在中间的一行中,您可以看到,用于构建设置的SWIFT_VERSION被特别更改为2.3。总的来说,你的播客应该是这样的:

target 'YourApp' do
  use_frameworks!

  # Pods for Weatherly
  pod 'Alamofire'

end

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
           config.build_settings['SWIFT_VERSION'] = '2.3'
        end
   end
end

Hope this helped :)

希望这有助于:)

#2


0  

It looks like you're not really using Swift 2.3.

看起来你并没有使用Swift 2.3。

  1. Go to Build Settings section of your target's settings.
  2. 去建立你的目标设置的设置部分。
  3. Search for Use Legacy Swift Language Version and set it to YES if you really want to use Swift 2.3
  4. 搜索使用遗留的Swift语言版本,如果您真的想使用Swift 2.3,请将其设置为YES
  5. Clean and build.
  6. 清洁和构建。

If that doesn't help, try the following:

如果这没有帮助,试试下面的方法:

  1. Open project.pbxproj file
  2. 开放的项目。pbxproj文件

You can find it in the *.xcodeproj: Right click -> Show package contents -> project.pbxproj)

你可以在*中找到它。xcodeproj:右键单击->显示包内容-> project.pbxproj)

  1. Search for SWIFT_VERSION. If there is any other value except 2.3, set it manually. For example SWIFT_VERSION = 3.0; -> SWIFT_VERSION = 2.3;
  2. 寻找SWIFT_VERSION。如果除了2.3之外还有其他值,请手动设置。例如SWIFT_VERSION = 3.0;- > SWIFT_VERSION = 2.3;
  3. Clean and build again.
  4. 清洁并再次构建。

The reason for manual editing of project.pbxproj file is that sometimes Xcode doesn't update all values for SWIFT_VERSION key. Faced this issue on 8.0, perhaps it was already fixed in 8.1

项目手工编辑的原因。pbxproj文件是有时Xcode不会更新SWIFT_VERSION键的所有值。在8.0的问题上,也许它已经固定在8.1了。