Create NSManaged Object subclass Errors

Hi.

I am really new to this ... so please bare with me ...I think that I am missing a step but I canot find anything that explains the many errors that I am seeing ......


  1. Create a new iOS project ... iOS Single View application; language:Swift, and Use Core Data,
  2. With the datamodel file, add an Entity 'Person' with two attibutes, age (int64) and name (string)
  3. Editor Menu ... Create NSManagedObject Subclass... Next/Next/Create (boxes all ticked on the way through)
  4. Two files are created both with errors all over the place.


The first file that is generated is 'Person+CoreDataClass.swift' :

import Foundation

import CoreData

@objc(Person)

public class Person: NSManagedObject {

}


There is one error in this file: 'Invalid redeclaration of 'Person' for the Public Class declaration.



The second file is 'Person+CoreDataProperties.swift':

import Foundation

import CoreData

extension Person {

@nonobjc public class func fetchRequest() -> NSFetchRequest<Person> {

return NSFetchRequest<Person>(entityName: "Person");

}

@NSManaged public var age: Int64

@NSManaged public var name: String?

}


There are 6 (six!) errors in this code ...

  1. extrension generates: 'Person is ambiguous for type lookup in this context'
  2. The public class function also generates 'Person is ambiguous for type lookup in this context'
  3. Both @NSManaged lines reports that they are 'only allowed on an instance property or method';
  4. As well as 'Extensions may not contain stored properties'




Why? ... or rather how can I have done something wrong so soon? ... all this code is generated by Xcode itself ...


Thanks.

Which version of Xcode are you using?


I'm pretty sure in recent versions of Xcode your step three is unnecessary because the file is being generated for you. That's part of the reason that you're getting so many errors--you've asked Xcode to create a duplicate of something that already exists, and now you have definitions in two places.


The manual file generation menu option hasn't been removed in the versions with automatic file generation because of the Programmer's Corrolaries to Murphy's Law, among them "Eventually every automatic process needs to be run manually at least once by someone somewhere."

Create NSManaged Object subclass Errors
 
 
Q