在Swift中有问题。我想为学校写一个程序。对于奇数尾巴,应显示A周,而对于B天则应显示偶数天。该日期可以读取。但是,如果我始终对ee进行编程,那么我总是会收到错误消息String。我不知道如何改变它。有人可以进一步帮助我吗?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var Datum: UILabel!
@IBOutlet weak var Monat: UILabel!
@IBOutlet weak var Woche: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let jetzt = Date()
let formatter = DateFormatter()
formatter.dateFormat = "d"
Datum.text = formatter.string(from: jetzt)
let jetzt2 = Date()
let formatter2 = DateFormatter()
formatter2.dateFormat = "M"
Monat.text = formatter2.string(from: jetzt2)
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func Check(_ sender: Any) {
if Datum.text = "3"
Woche.text = "A-Woche"
}
}
答案 0 :(得分:1)
尝试一下
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var Datum: UILabel!
@IBOutlet weak var Monat: UILabel!
@IBOutlet weak var Woche: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let jetzt = Date()
let formatter = DateFormatter()
formatter.dateFormat = "d"
Datum.text = formatter.string(from: jetzt)
let jetzt2 = Date()
let formatter2 = DateFormatter()
formatter2.dateFormat = "M"
Monat.text = formatter2.string(from: jetzt2)
}
@IBAction func Check(_ sender: Any) {
if Datum.text == "3"{
Woche.text = "A-Woche"
} else {
Woche.text = "B-Woche"
}
}
}