简体   繁体   中英

ios swift3 xcode8 coredata

I'm learning ios development with swift3. I made my tables and then I go to EDIT -> create NSManagedObject subclass. Problem is that generated classes has lots of errors here's the generated code

Store+CoreDataClass.swift
import Foundation
import CoreData

@objc(Store)
public class Store: NSManagedObject {

}

import Foundation
import CoreData


extension Store {

   @nonobjc public class func fetchRequest() -> NSFetchRequest<Store> {
      return NSFetchRequest<Store>(entityName: "Store");
   }

   @NSManaged public var name: String?
   @NSManaged public var toImage: Image?
   @NSManaged public var toItem: NSSet?

}

Store+CoreDataProperties.swift
// MARK: Generated accessors for toItem
extension Store {

    @objc(addToItemObject:)
    @NSManaged public func addToToItem(_ value: Item)

    @objc(removeToItemObject:)
    @NSManaged public func removeFromToItem(_ value: Item)

    @objc(addToItem:)
    @NSManaged public func addToToItem(_ values: NSSet)

    @objc(removeToItem:)
    @NSManaged public func removeFromToItem(_ values: NSSet)

}

And here's the error that it gives me

@NSManaged only allowed on an instance property or method}

So why is that? What I'm missing?

On Swift 3 you don't have to create NSManagedObject subclass, the system will generate it for you so you can access it without it. However if you do want to generate it anyway, go to the xcdatamodel and make sure to set the Codegen over the Data Model inspetor to be "Manual/None", and then generate it:

I've attached this image for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM