gpt4 book ai didi

ios - 在 Swift 项目中找不到接受类型 'CGSize' 的参数列表的类型 '(() -> _)' 的初始值设定项

转载 作者:搜寻专家 更新时间:2023-11-01 06:23:04 24 4
gpt4 key购买 nike

我正在学习斯坦福大学的类(class)并收到此错误:

Cannot find an initializer for type 'CGSize' that accepts an argument list of type '(() -> _)' 

本类(class)仅在几个月前讲授,但使用的是 Xcode 6.2 而不是 Xcode 6.3。我需要采取哪些不同的措施来更正此错误?

这是第 12 课 - 动态动画 - http://web.stanford.edu/class/cs193p/cgi-bin/drupal/

enter image description here

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()

}
}

}

最佳答案

首先,您输入的 CGFloat 不正确。它是 CGFloat 而不是 CGFLoat。

对于第二部分,将 dropSize 中的 '=' 更改为 ':':

var dropSize : CGSize {
let size = gameView.bounds.size.width / CGFloat(dropsPerRow)
return CGSize(width: size, height: size)
}

此外,这是我第一次看到在 Swift 中使用“=”而不是“:”,自它发布以来...

关于ios - 在 Swift 项目中找不到接受类型 'CGSize' 的参数列表的类型 '(() -> _)' 的初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29856333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com