countries.shuffles()
if sender.tag == correcAnwer {
title = "Correct"
score += 1
} else {
title = "Wrong"
score -= 1
}
let ac = UIAlertController(title: title, message: "Your score is \(score).", preferredStyle: .alert)
ac.addAction(UIAlertAction(title:"Continue",style:.deault, handler: askQuestion))
present(ac, animated: true)
UIAlertController()의 preferredStyle에는 두 가지 종류가 있다
.alert : 스크린 중앙에 메세지 박스를 띄우는 방식 / 상황 변화에 대해 알릴 때 사용
.actionSheet : 하단에서 위로 메세지 박스를 밀어 올리며 띄우는 방식 / 여러 옵션 중에서 선택하도록 요청할 때 사용
ac.addAction(UIAlertAction(...)) : alert에 버튼을 추가하기 위해 UIAlertAction 데이터 타입을 사용한다. 이 때 style에는 세 가지 종류가 있다.
.default :
.cancel : 해당 액션이 실행을 중지시키고 다른 것들을 변화시키지 않은 채로 끝나는 것을 나타냄
.destructive : 해당 액션이 데이터를 변화, 삭제시킨다는 것을 나타냄
(handler : askQuestion) : handler 매개변수는 버튼이 눌러졌을 때 실행되는 코드를 담을 클로져를 원한다. 코드로 작성해주어도 되지만, askQuestion() 메서드를 호출하도록 askQuestion을 전달해 주었다.
func askQuestion() {
}
func askQuestion(action: UIAlertAction!) {
}