Help us understand the problem. What is going on with this article?

【Swift】 alert表示のテンプレート

タイトル通りです。
入力チェック時のエラー表示や、入力完了時のメッセージ表示の際の、「とりあえずアラートダイアログでメッセージを表示したい(ダイアログのボタン押下による処理は無くてよい)」時に便利に使いまわせるメソッド。

開発環境

端末:MacBook Pro/MacOS 10.14.5(Mojave)
Xcode:10.2.1
Swift:5

実装内容

ソースサンプル

sample.swift
import UIKit

class secondViewController: UIViewController {
    var alertController: UIAlertController!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    func alert(title:String, message:String) {
        alertController = UIAlertController(title: title,
                                   message: message,
                                   preferredStyle: .alert)
        alertController.addAction(UIAlertAction(title: "OK",
                                       style: .default,
                                       handler: nil))
        present(alertController, animated: true)
    }

    @IBAction func tapButton(_ sender: Any) {
        alert(title: "サンプル",
              message: "メッセージ表示")
    }
}

画面表示

Screen Shot 2019-09-13 at 2.52.04.png

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away