我遇到过很多与此类似的问题,但很多都是针对旧版本的 Xcode,或者根本不起作用。我正在使用 Xcode 版本 8.3.2 (8E2002) 和 Swift 编码语言。我对编码了解不多,但我很年轻,渴望学习!我正在创建一个点击器游戏,它可以让您在游戏本身中每秒获得金钱。因此,如果您闲置 2 分钟,它会给您 120 美元(120 秒每秒 1 美元)。除此之外,您还可以通过单击主要对象来赚钱。到目前为止,这是我的编码:
import UIKit
class ViewController: UIViewController {
var score = 0
var add = 1
func addpersec() {
score += 1
}
//func used to add to the score based timer. Aka, adding 1 per second
@IBOutlet weak var scorecount: UILabel!
@IBAction func clicks(_ sender: Any) {
score += 1
scorecount.text = "Honey: \(score)"
}
@IBOutlet weak var Bees: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)
class ViewController: UIViewController {
var timer: Timer? = nil // Property
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(handleTimer), userInfo: nil, repeats: true)
}
func handleTimer(_ timer: Timer) {
print("Timer ticking!")
}
}
Run Code Online (Sandbox Code Playgroud)
要使计时器无效,请调用 self.timer?.invalidate()
| 归档时间: |
|
| 查看次数: |
910 次 |
| 最近记录: |