Skip to content

Instantly share code, notes, and snippets.

@creaaa
Created May 14, 2019 15:45
Show Gist options
  • Save creaaa/eec1e5963c2ea97948a000d8c75e97a0 to your computer and use it in GitHub Desktop.
Save creaaa/eec1e5963c2ea97948a000d8c75e97a0 to your computer and use it in GitHub Desktop.
import UIKit
class HogeClass {}
// 意味: このプロトコルに適合させるクラスは、
// 必ずこのクラス(HogeClass)のサブクラスでなくてはならない
// ≒ HogeClassを継承しないといけない
// (Self == HogeClass とは書けない)
protocol HogeProtocol where Self: HogeClass {
func hoge()
}
//
class FugaClass: HogeClass, HogeProtocol {
func hoge() { print("hoge!") }
}
// つまりこれがだめ
class PuyoClass: HogeProtocol {
func hoge() { print("hoge!") }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment