Ответ 1
В прокрутке Swift инициализатора удобства UIAlertView есть ошибка, вам нужно использовать простой инициализатор
let alert = UIAlertView()
alert.title = "Hey"
alert.message = "This is one Alert"
alert.addButtonWithTitle("Working!!")
alert.show()
Этот код стиля более верен для языка Swift. Инициализатор удобства кажется мне более Objective-C'ish. Просто мое мнение.
Примечание: UIAlertView устарел (см. Объявление), но Swift поддерживает iOS7, и вы не можете использовать UIAlertController на iOS 7
Просмотр декларации UIAlertView в Xcode
// UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead
class UIAlertView : UIView {
Предупреждение в Swift iOS 8 Only
var alert = UIAlertController(title: "Hey", message: "This is one Alert", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Working!!", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
Обновление для Swift 4.2
let alert = UIAlertController(title: "Hey", message: "This is one Alert", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "Working!!", style: UIAlertAction.Style.default, handler: nil))
self.present(alert, animated: true, completion: nil)