1
votes

This is my first app using Core Data, and I have introduced two new ManagedObjects subclasses. At first I wrote the two classes as two normal Swift classes, then I decided to make them ManagedObject subclasses by creating them as entities in the dataModel.

I then went Editor >> Create NSManagedObject Subclass... and then copied and pasted the code from the first class into the new class, and deleted the old class. This worked fine.

The second time around I tried the same thing, but I am having errors with the attributes this time around.

@objc(TimeValues)
class TimeSlot: NSManagedObject {

    var beginDate: NSDate //This line here
    var endDate: NSDate   //This line here
    var currentSeconds: NSNumber //This line here

The attributes all have the error Invalid redeclaration of 'beginDate' and stored property beginDate requires an initial value or should be NSManaged

And in the other TimeSlot extension file I am also getting redeclaration errors:

import Foundation
import CoreData

extension TimeSlot {

    @NSManaged var beginDate: NSDate?
    @NSManaged var endDate: NSDate?
    @NSManaged var currentSeconds: NSNumber?

}

I thought a redeclaration error was because I was declaring it somewhere else, but I have deleted the old folder and the other NSManagedObject subclass works fine. The only difference between the two is that the other one only has static variables.

Any help is appreciated, thanks!

1

1 Answers

0
votes

Did you check syntax problems? I had a similar problem caused by an extra empty import statement in files generated by Editor >> Create NSManagedObject Subclass... in Xcode 8.0:

import Foundation
import CoreData
import // <- delete this line