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 P<Element> { | |
| associatedtype Element | |
| var first: Element? { get } | |
| } | |
| extension Array : P { | |
| } | |
| let x: any P<Int> = [1, 2] |
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 P { | |
| associatedtype Element | |
| } |
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. 総称関数 | |
| func action<Value: P>(_ value: Value) { | |
| } | |
| // B. これは、総称関数? | |
| func action(_ value: P) { | |
| } | |
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
| struct MyType<Element> { | |
| var value: Element | |
| } | |
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
| guard var value else { | |
| } |
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 values = [1, 2, 3, 4, 5] | |
| var value: Int? { values.popLast() } | |
| while let value { | |
| print(value) | |
| } | |
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
| something(a) // "some A" | |
| something(b) // "some A" | |
| something(c) // "some A" | |
| something(a as A) // "Any" | |
| something(b as A) // "Any" | |
| something(c as A) // "Any" | |
| MemoryLayout.size(ofValue: a) // 8 | |
| MemoryLayout.size(ofValue: b) // 40 | |
| MemoryLayout.size(ofValue: c) // 40 |
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 A {} | |
| extension Int : A {} | |
| func something(_ value: Any) -> String { return "Any" } | |
| func something(_ value: some A) -> String { return "some A" } | |
| let a: Int = 0 | |
| let b: A = 0 | |
| let c = a as 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
| var value: Int? = 100 | |
| do { | |
| defer { | |
| value = nil | |
| } | |
| let value = value.map { $0 * 2 } ?? 0 | |
| print(value) | |
| } |
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
| let possibleNumber = "helloworld" | |
| let convertedNumber = Int(possibleNumber, radix: 36) |
NewerOlder