Last active
February 8, 2016 04:28
-
-
Save chris-hatton/7bc54c2eebea945fdfcf to your computer and use it in GitHub Desktop.
A test of inferred return types in Swift, both generic and overloaded nillable
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
import UIKit | |
class A : CustomDebugStringConvertible | |
{ | |
let message: String | |
required init( message: String ) { self.message = message } | |
var debugDescription: String { return message } | |
} | |
class AA : A {} | |
class AB : A {} | |
func test<SomeType:A>() -> SomeType | |
{ | |
return SomeType( message: "\(String(SomeType)) created through a non-nillable method invocation" ) | |
} | |
func test<SomeType:A>() -> SomeType? | |
{ | |
return SomeType( message: "\(String(SomeType)) created through a nillable method invocation" ) | |
} | |
let first : AA? = test() | |
let second : AA = test() | |
let third : AB? = test() | |
let fourth : AB = test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment