That Obj-C code doesn't look right. There's no need to override the 'view' property at all, since the superclass already defines it. Just set its value in the -loadView method.
What Travis's example seems to do is exploit behavior that, at least in the current Obj-C compiler, lets you alter the class of an inherited property. I guess this lets you avoid type-casts, but IMHO it's a hack — I've been coding in Obj-C and Cocoa since 2000 and I've never seen anyone do this before; I have my doubts whether the language design even intended for this to be legal.
If you really want to do this in Swift, the equivalent of @dynamic is @NSManaged, but according to
Apple's docs this is only for use in CoreData NSManagedObject subclasses, so I don't know if it works outside of that:
Like the @dynamic
attribute in Objective-C, the @NSManaged
attribute informs the Swift compiler that the storage and implementation of a property will be provided at runtime. However, unlike @dynamic
, the @NSManaged
attribute is available only for Core Data support.
—Jens