Swift X:代码间距错误在哪里?
有人能帮我吗?我需要编码,我需要帮助。我在寻找我放的任何额外括号,但没有看到任何帮助?这类功能的一个有用功能是右键单击文件中的某个位置,然后从弹出菜单中选择“结构->平衡分隔符”。这将突出显示开始和结束分隔符之间的所有代码。如果该代码块的分隔符丢失,它将向您发出嘟嘟声Swift X:代码间距错误在哪里?,swift,Swift,有人能帮我吗?我需要编码,我需要帮助。我在寻找我放的任何额外括号,但没有看到任何帮助?这类功能的一个有用功能是右键单击文件中的某个位置,然后从弹出菜单中选择“结构->平衡分隔符”。这将突出显示开始和结束分隔符之间的所有代码。如果该代码块的分隔符丢失,它将向您发出嘟嘟声 在您的例子中,类定义本身缺少右大括号。问题是什么?您能发布准确的错误消息或错误截图吗?@MidhunMP您在哪一行得到该错误?@MidhunMP在代码末尾有一个屏幕截图,您在类标记的代码结束括号中缺少最后一个} import UI
在您的例子中,类定义本身缺少右大括号。问题是什么?您能发布准确的错误消息或错误截图吗?@MidhunMP您在哪一行得到该错误?@MidhunMP在代码末尾有一个屏幕截图,您在类标记的代码结束括号中缺少最后一个}
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var QuestionLabel: UILabel!
@IBOutlet weak var Button1: UIButton!
@IBOutlet weak var Button2: UIButton!
@IBOutlet weak var Button3: UIButton!
@IBOutlet weak var Button4: UIButton!
var CorrectAnswer = String()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
RandomQuestions()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func RandomQuestions(){
var RandomNumber = arc4random() % 4
RandomNumber += 1
switch(RandomNumber){
case 1:
QuestionLabel.text = "Who is the best soccer player in the world?"
Button1.setTitle("Messi", forState: UIControlState.Normal)
Button2.setTitle("Neymar", forState: UIControlState.Normal)
Button3.setTitle("Bale", forState: UIControlState.Normal)
Button4.setTitle("James", forState: UIControlState.Normal)
CorrectAnswer = "2"
break
case 2:
QuestionLabel.text = "How many goals is a hat trick?"
Button1.setTitle("2", forState: UIControlState.Normal)
Button2.setTitle("5", forState: UIControlState.Normal)
Button3.setTitle("3", forState: UIControlState.Normal)
Button4.setTitle("7", forState: UIControlState.Normal)
CorrectAnswer = "3"
break
case 3:
QuestionLabel.text = "What number is Neymar?"
Button1.setTitle("2", forState: UIControlState.Normal)
Button2.setTitle("5", forState: UIControlState.Normal)
Button3.setTitle("3", forState: UIControlState.Normal)
Button4.setTitle("11", forState: UIControlState.Normal)
CorrectAnswer = "4"
break
case 4:
QuestionLabel.text = "What number is messi?"
Button1.setTitle("2", forState: UIControlState.Normal)
Button2.setTitle("10", forState: UIControlState.Normal)
Button3.setTitle("3", forState: UIControlState.Normal)
Button4.setTitle("7", forState: UIControlState.Normal)
CorrectAnswer = "2"
break
default:
break
}
}
@IBAction func Button1Action(sender: AnyObject) {
if (CorrectAnswer == "1"){
NSLog("You Are Correct")
}
else{
NSLog("YOu Are Wrong")
}
}
@IBAction func Button2Action(sender: AnyObject) {
if (CorrectAnswer == "2"){
NSLog("You Are Correct")
}
else{
NSLog("YOu Are Wrong")
}
}
@IBAction func Button3Action(sender: AnyObject) {
if (CorrectAnswer == "3"){
NSLog("You Are Correct")
}
else{
NSLog("YOu Are Wrong")
}
}
@IBAction func Button4Action(sender: AnyObject) {
if (CorrectAnswer == "4"){
NSLog("You Are Correct")
}
else{
NSLog("You Are Correct")
}
}