更新到 Xcode 7.1(从 6.4)导致 UIIMageView 动画损坏

Updated to Xcode 7.1 (from 6.4) caused UIIMageView animation broken

我升级了我的 Xcode 项目,该项目在 6.4 中编译得很好,但选择不升级到 Swift 2.0(我想先编译它,然后再引起更多错误)。

我遇到了数百个错误,现在大部分都已修复,但我无法弄清楚这一错误。这在 6.4 中有效:

var imgListArray:NSMutableArray = []
self.imageView.animationImages = imgListArray as [AnyObject]

我在 7.1.1 中得到错误:

'NSMutableArray' is not implicitly convertible to '[AnyObject]'; did you mean to use 'as' to explicitly convert?

如果我尝试编译器的建议,我会得到:

self.imageView.animationImages = imgListArray as [AnyObject] as [AnyObject]

这给了我错误:

Cannot assign value of type '[AnyObject]' to type '[UIImage]?'

以下是我修复错误的方法:

   var imgListArray = [AnyObject]()
        self.imageView.animationImages = imgListArray as! [UIImage]

您需要做的是将 imgListArray 声明为图像数组。 以下是如何做到这一点:

var imgListArray: [UIImage] = []
self.imageView.animationImages = imgListArray