【发布时间】:2015-12-16 08:41:25
【问题描述】:
我被要求将一个相当大的应用程序迁移到 Swift 2。编译器不断抛出分段错误:一个函数出现 11 个错误,出现在应用程序逻辑的不同模块中(唯一的区别是使用的变量):
func loadMoreContent() {
if let collection = self.ratingsCollection where collection.identifier != 0,
let totalEntries = collection.totalEntries,
let objects = self.ratings?.count where objects < totalEntries {
self.ratingsCollection = nil
collection.nextPage().onSuccess { (value) in
if let collection = value as? Collection<Rating> {
self.ratingsCollection = collection
} else {
self.ratingsCollection = Collection<Rating>(identifier: 0)
}
}.onFailure { error in
self.ratingsCollection = Collection<Rating>(identifier: 0)
}
}
}
以下是错误本身:
1. While type-checking 'loadMoreContent' at (path redacted).swift:46:3
2. While type-checking expression at [(path redacted).swift:54:9 - line:64:9]
RangeText="collection.nextPage().onSuccess { (value) in
if let collection = value as? Collection<Rating> {
self.ratingsCollection = collection
} else {
self.ratingsCollection = Collection<Rating>(identifier: 0)
}
}.onFailure { error in
self.ratingsCollection = Collection<Rating>(identifier: 0)
}"
3. While loading members for declaration 0x7fdda42ea2b0 at <invalid loc>
4. While deserializing 'producer' (FuncDecl #340)
乍一看,有人知道这个功能有什么问题吗?我应该添加它在 Xcode 6 / Swift 1.2 中没有变化的情况下编译。
【问题讨论】:
-
你能找出 loadMoreContent 中的哪一行导致了故障吗?也许首先将所有内容注释掉并逐行添加。我的疯狂猜测是它与'as有关? Collection
' 演员表。我认为了解更多有关您正在使用的 Collection 类的信息会有所帮助。 -
奇怪的是,在我更新 ReactiveCocoa 后错误消失了,它甚至没有在 Collection 类或函数本身中使用......我猜是在没有移交的情况下接管一个废弃的项目的乐趣.非常感谢您的意见@nwales
标签: swift compiler-errors swift2 xcode7