Visual Studio CodeでRubyデバッグを試してみました

Visual Studio CodeによるRubyのデバッグ | Developers.IOを参考にVisual Studio CodeでRubyデバッグを試してみました。ウオッチ式、コールスタックが使えるので十分実用できそうです。

今まで、Rubyデバッグ用にRubyMineを購入していたが、Visual Studio Codeで十分な気がしてきました。 f:id:unokun3:20170717163952p:plain

Java8日付API

WEB+DB vol.97 2017の「Java 8で直感的な日付/時間操作」という記事を参考にJava8日付APIを触ってみました。 Java8のDate and Time APIはJoda-Timeに基づいて作られた新しいAPIです。従来のDataやCalendarよりも簡単に日付操作をすることができます。

農業は太陽(太陽暦)、漁業(航海)は月(太陰暦)に関心があるという観点は始めて。興味深い。

リンク

UILabelのタップイベントを処理する

UILabelのタップイベントを処理して、ラベルに表示する値をアラートダイアログで入力する方法です。

UIラベルのisUserInteractionEnabledをtrueにして、touchesEndedで処理します。

class ViewController: UIViewController {
    let timerLabelTag = 10
    @IBOutlet weak var timerLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        timerLabel.tag = timerLabelTag
        timerLabel.isUserInteractionEnabled = true
    }

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        for touch: UITouch in touches {
            let tag = touch.view!.tag
            if (tag == timerLabelTag) {
                // アラートダイアログで入力する
                let alert = UIAlertController(title: "タイマー時間セットアップ", message: "時間(秒)を入力してください", preferredStyle: .alert)
                let saveAction = UIAlertAction(title: "セット", style: .default) { (action:UIAlertAction!) -> Void in
                    
                    let textField = alert.textFields![0] as UITextField
                    timerLabel = textField.text! 
                    }
                }
                
                let cancelAction = UIAlertAction(title: "キャンセル", style: .default) { (action:UIAlertAction!) -> Void in
                }
                
                // UIAlertControllerにtextFieldを追加
                alert.addTextField { (textField:UITextField!) -> Void in
                }
                
                alert.addAction(saveAction)
                alert.addAction(cancelAction)
                
                present(alert, animated: true, completion: nil)
            }
        }
    }
}

リンク

Excelを使って簡単にINSERT文を作る方法

今参加しているプロジェクトでは、データを挿入してテストすることがあるので、メモしておきます。 やっぱり、一つ一つInsert文を作成するより楽ですね。

リンク

swiftで変数に値が入っているかどうかチェックする

swiftでoptional変数に値が入っている(nilでない)ことをチェックする場合には、以下のようにします。

func isValid(value: String?) -> Bool
    if let _ = 何かの値 {
        return true
    }
    return false
}

_のところに変数にするとXcodeがワーニング(未使用変数)を出すのを回避できます。

iOS GameplayKitを使って見ました

@ITに、「iOS GameplayKitの「Agents, Goals, and Behaviors」で作る、鬼ごっごの鬼AI」という面白そうな記事がありましたので、試してみました。

GameplayKitを初めて使いましたが、簡単に使えるという印象を持ちました。 この連載には、AI的な要素もありそうで今後が楽しみです。

リンク