Skip to content

Instantly share code, notes, and snippets.

@el-hoshino
Last active November 6, 2018 04:46
Show Gist options
  • Save el-hoshino/4fac011e3198ddfcb28fe06e87a5e8e1 to your computer and use it in GitHub Desktop.
Save el-hoshino/4fac011e3198ddfcb28fe06e87a5e8e1 to your computer and use it in GitHub Desktop.
Swift で Class-Only Protocol を定義する ref: https://qiita.com/lovee/items/a686e11f00b31323e683
protocol SomeProtocol: class {
var aVariable: Int { get set }
func increase()
}
extension SomeProtocol {
func increase() {
self.aVariable += 1
}
}
class SomeClass: SomeProtocol {
var aVariable: Int
init() {
self.aVariable = 0
}
}
let some = SomeClass()
some.increase()
protocol SomeProtocol {
var aVariable: Int { get set }
mutating func increase()
}
extension SomeProtocol {
mutating func increase() {
self.aVariable += 1
}
}
class SomeClass: SomeProtocol {
var aVariable: Int
init() {
self.aVariable = 0
}
}
let some = SomeClass()
some.increase()
protocol ADelegate: class {
}
protocol SomeProtocol: AnyObject {
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment