【Swift】iPadで「Number Pad」にドルだの…→変なキーを押したら文字を消してアラートを出すコードを書きました！

<a href="http://blueroy.jimdo.com/about-blueroy-inc/" target="_blank">素人薬剤師プログラマ</a>の私。
体当たりでいろいろやっております。

＝
最新作「<a href="https://itunes.apple.com/jp/app/id982765022" target="_blank">漢方スクランブル</a>」。
調剤薬局で薬剤師が漢方をとってくる過程をイメージしたものなのですが
これの「漢方の包数」の回答のところに
<b>テキストフィールドをstringとして読んでくる→intの処理を入れている</b>ため、
<b>ユーザがテキストフィールドに数値以外を入れてくるとプログラムが落ちる</b>状態に。

というか、iPhoneのみでなく…ユニバーサルにしたら
<b>…iPadの「Number Pad」には
いろいろ数字じゃないものが表示されすぎ！</b>
※iPhoneのみの対応であれば普通のNumber Padが表示される
![写真 2015-04-17 16 29 21.png](https://qiita-image-store.s3.amazonaws.com/0/58253/5fdc42fe-5495-1df8-e755-c3021fabe4f8.png)
¥とか＆くらいならまだ許せますが![写真 2015-04-17 16 29 29.png](https://qiita-image-store.s3.amazonaws.com/0/58253/b22b0de3-633e-d4fd-f813-33f552cccd13.png)
なんと、Number Padのくせに英文字も！![写真 2015-04-17 16 29 48.png](https://qiita-image-store.s3.amazonaws.com/0/58253/4012d81c-75db-b7a6-c476-71e9386e90a8.png)
変な記号！!
![写真 2015-04-17 16 39 49.png](https://qiita-image-store.s3.amazonaws.com/0/58253/1671651b-ee47-bf05-89ab-37a17e532bf9.png)
更には年月日まで！！

＝
この状況を改善すべく、コードを書きました。
もっとエレガントな方法があればご教示いただければ幸いです。
なお、「テキストフィールド編集を検知する」方法は
Swiftサラリーマンさんの<a href="http://swift-salaryman.com/uitextfield.php" target="_blank">UITextfieldで文字を編集する</a>を参考にしました。
いつもありがとうございます！Swiftサラリーマンさん。

<b>intになりうる以外の文字をテキストフィールドに入れたらその文字を消し、
「ダメ！」という通知をだす</b>ようにしました。
arrayのところの文字列に着目。
<b>愚直に調べてひろいあげます。</b>これらの文字のうちいずれかが入っていると
テキストフィールドが消去され、回答ボタンが押せなくなる仕様です。

<div class="code-frame" data-lang="she'll">
<div class="code-lang"><span class="bold">FirstViewController.swift</span></div>
<div class="highlight"><pre>
class FirstViewController: UIViewController,UITextFieldDelegate{
//UITextFieldDeletate必須！
func textFieldDidEndEditing(textField: UITextField) -> Bool {
    func numbercheck(){
        //iPadのときのみ、数字以外入れてないかどうか調べる
        //水色のところに文字があるかどうかを判定してから動かす
        var str = hou.text
        let charArray = [" ","-","/",":",";","(",")","$","&","@",".",",","?","!","\'","\"","[","]","{","}","#","%","^","*","+","=","_","\\","|","~","<",">","£","€","¥","q","w","e","r","t","y","u","i","o","p","l","k","j","h","g","f","d","s","a","z","x","c","v","b","n","m","Q","W","E","R","T","Y","U","I","O","P","L","K","J","H","G","F","D","S","A","Z","X","C","V","B","N","M","あ","い","う","え","お","か","き","く","け","こ","さ","し","す","せ","そ","た","ち","つ","て","と","な","に","ぬ","ね","の","は","ひ","ふ","へ","ほ","ま","み","む","め","も","や","ゆ","よ","ら","り","る","れ","ろ","わ","を","ん","ー","「","」","？","！","。","、","ぁ","ぃ","ぅ","ぇ","ゎ","ぉ","っ","ゃ","ゅ","ょ","が","ぎ","ぐ","げ","ご","ざ","じ","ず","ぜ","ぞ","だ","ぢ","づ","で","ど","ば","び","ぶ","べ","ぼ","ぱ","ぴ","ぷ","ぺ","ぽ","年","月","日","時","分","１","２","３","４","５","６","７","８","９","０","，","．","：","×","÷","＋","−","＝","♪","☆","〒","→","〜","~","・","…","○","／","（","）"]
        for moji in charArray{
            var range = str.rangeOfString(moji)
            if range != nil {
                //変な文字が含まれている場合、入力した文字を強制的に消す
                textField.text = ""
		//回答ボタンが押せないようにする
		kaitouButton.enabled = false
           }
        }
    }
    let screenHeight = Int(UIScreen.mainScreen().bounds.size.height)
    if screenHeight == 1024{
        //iPadのときだけ変な文字が入ってないかどうか確認する
//        println("iPadだっせ")
        numbercheck()
    }
</pre></div>
</div>

いかがでしょうか。
このソフト「<a href="https://itunes.apple.com/jp/app/id982765022" target="_blank">漢方スクランブル</a>」は薬学生向き・新人薬剤師向けではありますが、
普通に算数ゲームとしても愉しんでいただけること請け合いですので
是非ダウンロードよろしくお願いいたします！
また旧作「<a href="http://blueroyjp.wix.com/blueroy#!app2/c1m8j" target="_blank">のんでいるくすり</a>（ひみつにしておける服薬メモ）」や
デビュー作"ICF inputter"（<a href="https://itunes.apple.com/jp/app/icf-inputter/id941536090?mt=8" target="_blank">iOS無料</a>・<a href="https://itunes.apple.com/jp/app/icf-inputter-free/id952433628?mt=8" target="_blank">iOS¥300広告なし</a>・<a href="https://play.google.com/store/apps/details?id=com.kaorys.icfinputter.icfinputter" target="_blank">Android</a>）も
よろしくお願いいたします！

　　　　　　　　　　　　　　　　Kaori Shige（重　歌織）