简体   繁体   English

iOS Swift3 XCode8 CoreData

[英]ios swift3 xcode8 coredata

I'm learning ios development with swift3. 我正在用swift3学习ios开发。 I made my tables and then I go to EDIT -> create NSManagedObject subclass. 我做了表,然后去编辑->创建NSManagedObject子类。 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} @NSManaged仅允许在实例属性或方法上使用}

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. 在Swift 3上,您不必创建NSManagedObject子类,系统将为您生成它,因此无需它即可访问它。 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: 但是,如果您确实希望生成它,请转到xcdatamodel并确保将Data Model inspetor上的Codegen设置为“ Manual / None”,然后生成它:

I've attached this image for you 我已为您附上这张图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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