Hello, everyone I am a person who is entering iOS programming this time.
I am using xcode 8.2.1 version that I installed a few days ago.
I'm studying through the iOS programming book by Aaron Hillis.
There is a blockage in creating the Quiz application in Chapter 1 of the book.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
questionLabel.text = questions[currentQuestionIndex]
}
@IBOutlet var questionLabel: UILabel!
@IBOutlet var answerLabel: UILabel!
let questions: [String] = ["What's Yejin's phone number?(no-)",
"What's Yejin's is birth day?(yyyy,mm,dd)",
"What's Seung Hyun's birth day?(yyyy,mm,dd)"]
let answers: [String] = ["01091967621",
"1993,05,25",
"1992,11,02"]
var currentQuestionIndex: Int = 0
@IBAction func showNextQuestion(sender: AnyObject) {
currentQuestionIndex = (currentQuestionIndex++)%listOfQuestions.count
if currentQuestionIndex == questions.count {
currentQuestionIndex = 0
}
let question: String = questions[currentQuestionIndex]
questionLabel.text = question
answerLabel.text = "???"
}
@IBAction func showAnswer(sender: AnyObject) {
let answer: String = answers[currentQuestionIndex]
answerLabel.text = answer
}
}
Where currentQuestionIndex=(currentQuestionIndex++)%listOfQuestion.count
There's a blockage.
The error message is Use of unresolved identifier 'listOfQuestions'.
At first, I only wrote ++currentQuestionIndex
as it was written in the book.
Then in swift3, the phrase ++ is missing should not appear.
That's why I put it in because I heard that that's the code that allows questions to circulate even if you keep pressing the question label while searching on the Internet. I want that function, too.
I want to build and run the app rather than the function. I don't know how to handle this. Please answer me. Thank you for reading it.
swift ios iphone xcode
Use of unresolved identifier 'listOfQuestions'
This part of it is because you use variables that are not defined. The variable listOfQuestions is not declared on the code.
If the simple quiz is in a cyclic form, this will cause the currentQuestionIndex to be +1 and circulate.
@IBAction func showNextQuestion(sender: AnyObject) {
currentQuestionIndex += 1
if currentQuestionIndex == questions.count {
currentQuestionIndex = 0
}
let question: String = questions[currentQuestionIndex]
questionLabel.text = question
}
From Swift 3.0
SE-0004 : Remove the ++ and — operators (++/– delete operator)
The ++/ -- operator has been deleted, so it is correct to use += 1 or -= 1 instead.
Please refer to this site for changes to Swift3.0. Swift 3.0 changes
© 2024 OneMinuteCode. All rights reserved.