Last active
December 2, 2015 01:53
-
-
Save tjw/e08865cfbb979605f27f to your computer and use it in GitHub Desktop.
Corruption when assigning to stored properties in classes using generics
This file contains 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 Cocoa | |
class A<T> : NSViewController { | |
var x:T? = nil | |
override init?(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { | |
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) | |
} | |
} | |
class B : A<NSString> { | |
override init?(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { | |
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) | |
} | |
} | |
let b = B(nibName:"bbb", bundle:NSBundle.mainBundle())! | |
print("b.nibName = \(b.nibName)") | |
b.x = "foo" as NSString | |
print("b.nibName = \(b.nibName)") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to show more clearly that the write to the generic property overwrites an ivar on the superclass.