Created
October 15, 2014 19:03
-
-
Save joshdholtz/a9b2ddf907f2a5f2a2f6 to your computer and use it in GitHub Desktop.
Why is C not C?
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
// | |
// ViewController.swift | |
// SwiftTest | |
// | |
// Created by Josh Holtz on 8/3/14. | |
// Copyright (c) 2014 Josh Holtz. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
var a = Maker<A>.make(); // Adheres to Base | |
a.talk() // Outputs "Aaaaaa" | |
var b = Maker<B>.make(); // Adheres to Base | |
b.talk() // Outputs "Bbbbbb" | |
var c = Maker<C>.make(); // Extends B which adheres to base | |
c.talk() // Outputs "Bbbbbb" but I'm expecting "Cccccc" | |
var d = Maker<D>.make(); // Extends B and adheres to Base | |
d.talk() // Outputs "Dddddd" | |
} | |
} | |
class Maker<T:Base> { | |
class func make() -> T { | |
return T() | |
} | |
} | |
protocol Base { | |
init() | |
func talk() | |
} | |
class A: Base { | |
required init() {} | |
func talk() { | |
println("Aaaaaa") | |
} | |
} | |
class B: Base { | |
required init() {} | |
func talk() { | |
println("Bbbbbb") | |
} | |
} | |
class C: B { | |
required init() { super.init() } | |
override func talk() { | |
println("Cccccc") | |
} | |
} | |
class D: B, Base { | |
required init() { super.init() } | |
override func talk() { | |
println("Dddddd") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is fixed in Xcode 6.1.1.