Hello everyone,
I am a beinner and am learning swift from the apple e-book. I have been doing the apple pie project and am getting this error.I checked all the connections, they seemed alright.
my code is as follows:
view Controller:
< class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
/
newRound()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
/
}
@IBOutlet weak var treeImageView: UIImageView!
@IBOutlet weak var correctWordLabel: UILabel!
@IBOutlet weak var scoreLabel: UILabel!
@IBOutlet var letterButtons: [UIButton]!
@IBAction func buttonPressed(_ sender: UIButton) {
sender.isEnabled = false
let letterString = sender.title(for: .normal)!
let letter = Character(letterString.lowercased())
currentGame.playerGuessed(letter: letter)
updateUI()
}
var listOfWords = ["buccaneer", "swift", "glorious", "incandescent", "bug", "program"]
let incorrectMovesAllowed = 7
var totalWins = 0
var totalLosses = 0
var currentGame: Game!
func newRound(){
let newWord = listOfWords.removeFirst()
currentGame = Game(word: newWord, incorrectMovesRemaining: incorrectMovesAllowed, guessedLetter: [])
updateUI()
}
func updateUI() {
scoreLabel.text = "Wins: \(totalWins), Losses: \(totalLosses)"
treeImageView.image = UIImage(named: "Tree \(currentGame.incorrectMovesRemaining)")
}
} >
file named Game.swift includes:
<
struct Game{
var word: String
var incorrectMovesRemaining: Int
var guessedLetter: [Character]
mutating func playerGuessed (letter: Character){
guessedLetter.append(letter)
if !word.characters.contains(letter){
incorrectMovesRemaining -= 1
}
} >
The error im getting is:
2017-07-07 19:12:26.026005+0800 Apple Pie[9679:2058413] -[Apple_Pie.ViewController buttobPressed:]: unrecognized selector sent to instance 0x100c08110
2017-07-07 19:12:26.026885+0800 Apple Pie[9679:2058413] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Apple_Pie.ViewController buttobPressed:]: unrecognized selector sent to instance 0x100c08110'
*** First throw call stack:
(0x183502fe0 0x181f64538 0x183509ef4 0x183506f54 0x183402d4c 0x189662010 0x189661f90 0x18964c504 0x189661874 0x189661390 0x18965c728 0x18962d33c 0x189e27014 0x189e21770 0x189e21b9c 0x1834b142c 0x1834b0d9c 0x1834ae9a8 0x1833deda4 0x184e48074 0x189692058 0x1000fd210 0x1823ed59c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Note that the app is not completed, i am completing it according to the stages specified in the e-book.