Skip to content

Instantly share code, notes, and snippets.

@joshdholtz
Created October 15, 2014 19:03
Show Gist options
  • Save joshdholtz/a9b2ddf907f2a5f2a2f6 to your computer and use it in GitHub Desktop.
Save joshdholtz/a9b2ddf907f2a5f2a2f6 to your computer and use it in GitHub Desktop.
Why is C not C?
//
// 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")
}
}
@regnerjr
Copy link

This is fixed in Xcode 6.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment