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
| var statusCode = 200 | |
| switch statusCode { | |
| case 400..<500 : | |
| print("400台ダヨ") | |
| default: | |
| print("知らないヨ") | |
| } |
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
| var statusCode = 200 | |
| if 400..<500 ~= statusCode { | |
| print("400台ダヨ") | |
| } else { | |
| print("知らないヨ") | |
| } |
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
| class hoge { | |
| var currentIndex: Int = NSNotFound | |
| } |
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 name: String { get } | |
| } | |
| class A {} | |
| class B: A {} | |
| extension A: SomeProtocol {} | |
| extension SomeProtocol where Self: A { | |
| var name: String { return "My name is A" } | |
| } |
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 name: String { get } | |
| } | |
| class A {} | |
| class B: A {} | |
| extension A: SomeProtocol {} | |
| extension SomeProtocol where Self: A { | |
| var name: String { return "My name is A" } | |
| } |
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
| // A とそのサブクラス B が、"プロパティnameを持つ" SomeProtocolに準拠することを宣言。 | |
| class A {} | |
| class B: A {} | |
| protocol SomeProtocol { var whatYourName: Void { get } } | |
| extension A: SomeProtocol {} | |
| // Aにnameのデフォルト実装を用意 | |
| extension SomeProtocol where Self: A { | |
| var whatYourName: Void { print("My name is A") } | |
| } | |
| // BはAを継承していますが、更にデフォルト実装を上書きします |
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
| // A とそのサブクラス B が、"プロパティnameを持つ" SomeProtocolに準拠することを宣言。 | |
| class A {} | |
| class B: A {} | |
| protocol SomeProtocol { var name: String { get } } | |
| extension A: SomeProtocol {} | |
| // Aにnameのデフォルト実装を用意 | |
| extension SomeProtocol where Self: A { | |
| var name: String { return "My name is A" } | |
| } |
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 PhoneType{ | |
| var number:String { get } | |
| func callTo(number:String) | |
| } | |
| extension PhoneType { | |
| func callTo(number:String) { | |
| print("Call to \(number) from \(self.number)") | |
| } |
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
| class File { | |
| var content: Content { | |
| return Content(path:self.path) | |
| } | |
| } |
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
| class MyClass { | |
| lazy var calculate1: () -> Int = self.calculate | |
| lazy var calculate2: () -> Int = { | |
| self.calculate() | |
| }() | |
| } | |
| // calculate1 は 型 () -> Int より、calculate2と同じ、クロージャーが代入される。見た目はselfをキャプチャしていないかのように見えてしまうけど、calculate2がselfに循環参照を起こすのと同じように、calculate1も循環参照を生む。 |