Using Swift property observers breaks @NSManaged

Originator:neocool2
Number:rdar://19688217 Date Originated:02-Feb-2015 09:15 PM
Status:Open Resolved:
Product:iOS SDK Product Version:8.1
Classification:Serious Bug Reproducible:Always
 
Summary:

Using property observers on a @NSManaged property in Swift leads to runtime crashes. 

Consider an NSManagedObject defined like this:

class Entity: Base {
    // Comment this and everything works as expected \o/
    override var lol: String { willSet {} }
}

class Base: NSManagedObject {
    @NSManaged var lol: String
}

Using the given property will result in a runtime crash:

let entity = NSEntityDescription.insertNewObjectForEntityForName("Entity", inManagedObjectContext: managedObjectContext!) as Entity
entity.lol = "LOL!"

Steps to Reproduce:

Run the attached example project. 

Expected Results:

It works, just as it does without property observers (comment line 14 of Entity.swift to see that behaviour). Alternatively, it could not compile if there is no way to support Swift property observers on @NSManaged properties.

Actual Results:

Crash:

(lldb) bt
* thread #1: tid = 0x1e4ca3, 0x0000000000000000, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000000000000
  * frame #1: 0x000000010f6c7f22 LOLSwift`LOLSwift.AppDelegate.application (application=0x00007fdbca40f280, launchOptions=None, self=0x00007fdbca41c520)(ObjectiveC.UIApplication, didFinishLaunchingWithOptions : Swift.Optional<Swift.Dictionary<ObjectiveC.NSObject, Swift.AnyObject>>) -> Swift.Bool + 738 at AppDelegate.swift:20
   […]

Regression: -

Notes: -

Comments

For completeness sake, the sample can be found here as well: https://www.dropbox.com/s/hmo8h4mkan25qtq/LOLSwift.zip?dl=0


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!