我正在与斯坦福课程一起工作并收到此错误:
Cannot find an initializer for type 'CGSize' that accepts an argument list of type '(() -> _)'
本课程仅在几个月前教授,但使用的是 Xcode 6.2 而不是 Xcode 6.3。我需要做些什么来纠正这个错误?
这是第 12 课 - 动态动画 - http://web.stanford.edu/class/cs193p/cgi-bin/drupal/
import UIKit
class DropItViewController: UIViewController {
@IBOutlet weak var gameView: UIView!
var dropsPerRow = 10
var dropSize = CGSize {
let size = gameView.bounds.size.width / CGFloat(dropsPerRow)
return CGSize(width: size, height: size)
}
@IBAction func drop(sender: UITapGestureRecognizer) {
drop()
}
func drop() {
var frame = CGRect(origin: CGPointZero, size: dropSize)
frame.origin.x = CGFloat.random(dropsPerRow) * dropSize.width
let dropView = UIView(frame: frame)
dropView.backgroundColor = UIColor.random
gameView.addSubview(dropView)
}
}
private extension CGFLoat {
static func random(max: Int) -> CGFloat {
return CGFloat(arc4random() % UInt32(max))
}
}
private extension UIColor {
class var random: UIColor {
switch arc4random()%5 {
case 0: return UIColor.greenColor()
case 1: return UIColor.blueColor()
case 2: return UIColor.orangeColor()
case 3: return UIColor.redColor()
case 4: return UIColor.purpleColor()
default: return UIColor.blackColor()
}
}
}