Last active
November 6, 2018 04:46
-
-
Save el-hoshino/4fac011e3198ddfcb28fe06e87a5e8e1 to your computer and use it in GitHub Desktop.
Swift で Class-Only Protocol を定義する ref: https://qiita.com/lovee/items/a686e11f00b31323e683
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ADelegate: class { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol SomeProtocol: AnyObject { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment