SwiftでStoryboardを使わずにコードだけで画面のレイアウトを書く際に、毎回おまじないのように書くコード(translatesAutoresizingMaskIntoConstraintsやNSLayoutConstraintなど)が多いので、コマンド一発である程度補完できるようになる、ちょっとだけ便利なSourceEditorExtensionを作ってみました。
選択範囲にある変数に対して、translatesAutoresizingMaskIntoConstraints と、 topAnchor, leftAnchor, rightAnchor, bottomAnchor の制約を一括で書くことができます。ちなみに複数選択にも対応しています。
sampleView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
sampleView.topAnchor.constraint(equalTo: <#targetView#>.topAnchor),
sampleView.leftAnchor.constraint(equalTo: <#targetView#>.leftAnchor),
sampleView.rightAnchor.constraint(equalTo: <#targetView#>.rightAnchor),
sampleView.bottomAnchor.constraint(equalTo: <#targetView#>.bottomAnchor)
])
リポジトリからgit cloneしてarchive buildした中身を開くとxcode上で使えるようになるので、お好きなキーバインドを割り当てて使ってみてください。中身のコードは結構簡単なのでカスタムしてもいいと思います。よかったらgitのスターください。笑