New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-2673] @NSManaged property can't satisfy protocol requirement #45278
Comments
@slavapestov, possibly related to some of the eager synthesis of accessors for protocols? |
Relatedly, starting with Swift 3.0.1 (Xcode 8.1 beta 2) having the managed properties declared in an extension rather than in the class itself (similar to how Xcode generates subclasses) produces the error, "Extensions may not contain stored properties", along with a segfault.
|
@ChristopherRogers, do you have a self-contained example of that? (Rather than guess at what options to use in Xcode to match your situation.) |
I don't see the behavior Christopher is describing on master with this extension, either in the same source file as the class or in a separate one.
|
…unless like Charlie's case this only shows up when you have an |
Comment by Charlie Monroe (JIRA) BTW @objc(XUObject)
public class XUObject: NSManagedObject {}
protocol XUMyProtocol {
func sayHello()
}
extension XUObject: XUMyProtocol {
func sayHello() {
print("Hello")
}
}
let moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
let model = NSManagedObjectModel.mergedModel(from: [Bundle.main])!
moc.persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: model)
let obj = XUObject(entity: NSEntityDescription.entity(forEntityName: "XUObject", in: moc)!, insertInto: moc)
let foo = (obj as Any) as? XUMyProtocol // nil! |
Ah, yeah, that's a longstanding issue. :-( |
It seems you already figured it out while I was busy sleeping, but yes, it seems that the error only shows up when it's a import CoreData
class MyEntity: NSManagedObject { }
extension MyEntity {
@NSManaged public var thingy: String?
@NSManaged public var relationship: MyEntity?
}
@objc
protocol ThingyProvider {
var thingy: String? { get }
}
extension MyEntity: ThingyProvider { } |
Comment by Charlie Monroe (JIRA) @belkadan - actually I've tested now again and it seems to be working with Xcode 8 (the non- |
Just wanted to let you know that this still isn't working in the latest Xcode beta (8.1 beta (8T47)). You can test it with the sample code I posted in the comment above. |
Environment
macOS 10.12 GM, Xcode 8 (final)
Additional Detail from JIRA
md5: a342417346a61fd647db73f0c7929e52
cloned to:
relates to:
Issue Description:
I don't know if this should be a radar issue, or an issue here - please let me know if I should refile this as a radar. Consider the following code:
This produces an error that "Stored property 'entityID' requires an initial value or should be
@NSManaged
". Adding a default value, of course produces an error that "@NSManaged
property cannot have an initial value".The text was updated successfully, but these errors were encountered: