Using Swift property observers breaks @NSManaged

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

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 = "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:


(lldb) bt
* thread #1: tid = 0x1e4ca3, 0x0000000000000000, queue = '', 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: -


For completeness sake, the sample can be found here as well:

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at 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!