LoginSignup
1
0

More than 5 years have passed since last update.

[Swift] protocolを使ったテクニック Self縛り

Posted at

Self縛り

  • ある特定の型に依存したデフォルト実装が行える
  • ただし縛る方の型がそのプロトコルを適合している必要がある
Self縛り例.swift
protocol P {}
// UIViewControllerにPを適合することで初めてSelf縛りにUIViewControllerが使える
extension UIViewController: P {}

// Self縛り
extension P where Self: UIViewController {
// UIViewControllerに依存したデフォルト実装が行える
}

Warning: Self縛りという言葉は私の造語です。


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0