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<E> { ... } | |
| let p: P<String> |
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 { var v: String { get } } | |
| func f() -> P { | |
| struct InnerType: P { | |
| let v = "inner" | |
| } | |
| return InnerType() | |
| } | |
| f().v // inner |
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
| // unowned = unowned(safe) | |
| unowned(safe) var safe: AnyObject | |
| { [unowned(safe) a] in /* ... */ } | |
| // like `__unsafe_unretained` | |
| unowned(unsafe) var unsafe: AnyObject | |
| { [unowned(unsafe) a] in /* ... */ } |
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
| // > Updated the discussion of protocol extensions in Extension Declaration now that final isn’t allowed in them. | |
| // https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/RevisionHistory.html | |
| // https://web.archive.org/web/20170221062722/https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html | |
| // https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/doc/uid/TP40014097-CH34-ID378 | |
| class A {} | |
| extension A { | |
| final func f() {} | |
| } | |
| A().f() |
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
| enum Enum { | |
| case a | |
| case b | |
| @_downgrade_exhaustivity_check | |
| case c | |
| } | |
| // Compile: OK (warning) | |
| switch Enum.a { | |
| case .a: break |
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
| enum E<T: ExpressibleByIntegerLiteral>: T where T: Equatable { | |
| case a = 1 | |
| } | |
| struct MyType: ExpressibleByIntegerLiteral, Equatable { | |
| let v: String | |
| init(integerLiteral value: IntegerLiteralType) { v = String(value) } | |
| static func ==(lhs: MyType, rhs: MyType) -> Bool { return true } | |
| } |
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
| enum E<T: ExpressibleByIntegerLiteral>: T where T: Equatable { | |
| case a = 1 | |
| } | |
| // ... | |
| let ei: E<Int> = .a | |
| let et: E<MyType> = .a | |
| let i: E<Int> = E<Int>.a.rawValue |
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
| enum E<T: ExpressibleByIntegerLiteral>: T where T: Equatable { | |
| case a = 1 | |
| } |
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
| public static final void f() { | |
| Integer v = Integer.valueOf(300); | |
| Integer v2 = Integer.valueOf(300); | |
| boolean var10000; | |
| if(v == v2) { | |
| var10000 = true; | |
| } else { | |
| var10000 = false; | |
| } |
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 S { | |
| fun f(v: Int): String = "f" | |
| } | |
| fun main() { | |
| var sf: (S, Int) -> String = S::f | |
| var _sf: S.(Int) -> String = sf | |
| val sf1: String = sf(S(), 1) | |
| val sf2: String = _sf(S(), 1) | |
| } |