Alamofire 使用 CocoaPods 和 xcode 6.3

Posted

技术标签:

【中文标题】Alamofire 使用 CocoaPods 和 xcode 6.3【英文标题】:Alamofire using CocoaPods and xcode 6.3 【发布时间】:2015-04-11 17:12:20 【问题描述】:

总的来说,我对 swift 和 xCode 有点陌生,我已经安装了 Cocoapods 并有一个新的 xcode 项目。

我能够添加其他库,但是当我尝试加载 alamofire 库时,我收到大约 48 个错误。

我的 Podfile 看起来像这样:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'TwilioSDK'
pod 'Alamofire', '~> 1.2'

当我尝试构建应用程序时,我得到以下信息:

/****/Pods/Alamofire/Source/Alamofire.swift
/****/Pods/Alamofire/Source/Alamofire.swift:82:93: Expected type after 'as'
/****/Pods/Alamofire/Source/Alamofire.swift:222:19: Static properties are only allowed within structs and enums; use 'class' to declare a class property
/****/Pods/Alamofire/Source/Alamofire.swift:234:19: Static properties are only allowed within structs and enums; use 'class' to declare a class property
/****/Pods/Alamofire/Source/Alamofire.swift:241:84: Expected type after 'as'
/****/Pods/Alamofire/Source/Alamofire.swift:241:84: Expected ',' separator
/****/Pods/Alamofire/Source/Alamofire.swift:241:84: Expected expression in list of expressions
/****/Pods/Alamofire/Source/Alamofire.swift:263:59: Expected type after 'as'
/****/Pods/Alamofire/Source/Alamofire.swift:268:10: Consecutive statements on a line must be separated by ';'
/****/Pods/Alamofire/Source/Alamofire.swift:821:61: Expected type after 'as'
/****/Pods/Alamofire/Source/Alamofire.swift:937:43: Expected '' after 'if' condition
/****/Pods/Alamofire/Source/Alamofire.swift:939:13: Braced block of statements is an unused closure
/****/Pods/Alamofire/Source/Alamofire.swift:942:14: Consecutive statements on a line must be separated by ';'
/****/Pods/Alamofire/Source/Alamofire.swift:942:15: Expected expression
/****/Pods/Alamofire/Source/Alamofire.swift:942:20: Braced block of statements is an unused closure
/****/Pods/Alamofire/Source/Alamofire.swift:968:59: Expected '' after 'if' condition
/****/Pods/Alamofire/Source/Alamofire.swift:972:70: Expected '' after 'if' condition
/****/Pods/Alamofire/Source/Alamofire.swift:1141:65: Expected type after 'as'
/****/Pods/Alamofire/Source/Alamofire.swift:1176:65: Expected type after 'as'
/****/Pods/Alamofire/Source/Alamofire.swift:1176:65: Expected ',' separator
/****/Pods/Alamofire/Source/Alamofire.swift:1176:65: Expected expression in list of expressions
/****/Pods/Alamofire/Source/Alamofire.swift:1260:69: Expected type after 'as'
/****/Pods/Alamofire/Source/Alamofire.swift:1335:67: Expected type after 'as'
/****/Pods/Alamofire/Source/Alamofire.swift:1335:67: Expected ',' separator
/****/Pods/Alamofire/Source/Alamofire.swift:1335:67: Expected expression in list of expressions
/****/Pods/Alamofire/Source/Alamofire.swift:1348:71: Expected '' after 'if' condition
/****/Pods/Alamofire/Source/Alamofire.swift:1351:9: Braced block of statements is an unused closure
/****/Pods/Alamofire/Source/Alamofire.swift:1379:43: Expected '' after 'if' condition
/****/Pods/Alamofire/Source/Alamofire.swift:1381:9: Braced block of statements is an unused closure
/****/Pods/Alamofire/Source/Alamofire.swift:222:12: Static variables not yet supported
/****/Pods/Alamofire/Source/Alamofire.swift:234:12: Static variables not yet supported
/****/Pods/Alamofire/Source/Alamofire.swift:241:51: Type '()' does not conform to protocol 'SequenceType'
/****/Pods/Alamofire/Source/Alamofire.swift:253:33: Function produces expected type 'String'; did you mean to call it with '()'?
/****/Pods/Alamofire/Source/Alamofire.swift:106:43: Use of unresolved identifier 'mutableURLRequest'
/****/Pods/Alamofire/Source/Alamofire.swift:122:17: Use of unresolved identifier 'mutableURLRequest'
/****/Pods/Alamofire/Source/Alamofire.swift:123:17: Use of unresolved identifier 'mutableURLRequest'
/****/Pods/Alamofire/Source/Alamofire.swift:127:17: Use of unresolved identifier 'mutableURLRequest'
/****/Pods/Alamofire/Source/Alamofire.swift:128:17: Use of unresolved identifier 'mutableURLRequest'
/****/Pods/Alamofire/Source/Alamofire.swift:131:28: Use of unresolved identifier 'mutableURLRequest'
/****/Pods/Alamofire/Source/Alamofire.swift:134:17: Use of unresolved identifier 'mutableURLRequest'
/****/Pods/Alamofire/Source/Alamofire.swift:190:19: Operand of postfix '!' should have optional type; type is 'NSURL'
/****/Pods/Alamofire/Source/Alamofire.swift:939:13: Type of expression is ambiguous without more context
/****/Pods/Alamofire/Source/Alamofire.swift:942:20: Type of expression is ambiguous without more context
/****/Pods/Alamofire/Source/Alamofire.swift:970:13: Type of expression is ambiguous without more context
/****/Pods/Alamofire/Source/Alamofire.swift:1312:38: Operand of postfix '!' should have optional type; type is 'NSURL'
/****/Pods/Alamofire/Source/Alamofire.swift:1333:65: Operand of postfix '!' should have optional type; type is 'NSURL'
/****/Pods/Alamofire/Source/Alamofire.swift:1351:9: Type of expression is ambiguous without more context
/****/Pods/Alamofire/Source/Alamofire.swift:1382:39: Use of unresolved identifier 'escapedBody'
/****/Pods/Alamofire/Source/Alamofire.swift:1385:35: Operand of postfix '!' should have optional type; type is 'NSURL'

【问题讨论】:

查看我的回答here。一切都为公众正常工作。我当然会尝试@mattt 对pod update 的建议以及其他常见的 CocoaPods 故障排除策略。 也试过pod update这并没有解决问题。 好吧,原来我的 Xcode 不在 6.3 上。检查您的版本并转到pod update @mattt 我在 1.2 也遇到了这个问题,我降级到了 1.1.5。 【参考方案1】:

我遇到了同样的问题,但是通过降级到较低版本的 Alamofire (1.1.4) 并手动安装而不是使用 cocoapods 来解决这个问题。

【讨论】:

如果您为 iOS 设备构建而不是为模拟器构建,最新版本的 Alamofire 在 XCode 6.3 中工作。在发布新版本的 Alamofire 之前,您可以使用此方法。这对我有用。【参考方案2】:

对不起,误导性问题,我以为我已经更新了 xcode,但我没有。对于使用 xCode 6.2,选择 1.0.0 版本就可以了。

感谢解答

【讨论】:

以上是关于Alamofire 使用 CocoaPods 和 xcode 6.3的主要内容,如果未能解决你的问题,请参考以下文章

无法添加Alamofire与cocoapods项目

Cocoapods:制作 Cocoapod - 导入 Alamofire 和其他库

Alamofire 不会使用 Cocoapods 构建空的 Swift 项目

为啥“验证您的包标识符 'org.cocoapods.Alamofire' 是不是正确。”?

Alamofire 和 SwiftyJSON 错误

同时使用带有框架和静态库的 CocoaPods