Skip to content

Instantly share code, notes, and snippets.

View chris-hatton's full-sized avatar
👦
Intrepid

Chris Hatton chris-hatton

👦
Intrepid
View GitHub Profile
@chris-hatton
chris-hatton / nillableReturnTypeTest.swift
Last active February 8, 2016 04:28
A test of inferred return types in Swift, both generic and overloaded nillable
import UIKit
class A : CustomDebugStringConvertible
{
let message: String
required init( message: String ) { self.message = message }
var debugDescription: String { return message }
}
protocol ProtocolA {}
protocol ProtocolB {}
func overloadingTest ( obj: String ) -> String
{
return "It's a String"
}
func overloadingTest ( obj: Int ) -> String // This compiles fine, and the appropriate 'topLevelTest' function is called
@chris-hatton
chris-hatton / GenericOverloadedFunctionTest.swift
Last active December 31, 2015 21:36
Significance of top-level definition of overloaded functions
protocol ProtocolA {}
protocol ProtocolB {}
func overloadingTest <T where T: ProtocolA>( obj: T ) -> String
{
return "It's an implementation of Protocol A"
}
func overloadingTest <T where T: ProtocolB>( obj: T ) -> String // This compiles fine, and the appropriate 'topLevelTest' function is bound
@chris-hatton
chris-hatton / SelfGenericTypeTest.swift
Last active November 9, 2015 19:27
A test to see whether Swift's Generics system can carry through a self-derived type, which is possible, and often useful, in Java.
class A<SelfType : A<SelfType>>
{
}
class B : A<B> // Line fails to compile with: "'A' requires that 'B' inherit from 'A<B>'" even though it does
{
}
@chris-hatton
chris-hatton / example.swift
Last active August 3, 2017 17:57
Swift Protocol Extension and Generics
protocol MyProtocol
{
typealias GenType
func doSomething(param: GenType)
}
class MyObject<T> : MyProtocol
{
typealias GenType = T