How to create and store managed objects containing data using Swift 3.0 in Xcode 8.2

I get the error message "use of unresolved identifier" Contacts "(this is the name that I named Entity in my" fileName.xcdatamodeld ").

import UIKit
import CoreData

class ViewController: UIViewController {

    let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext         
   override func viewDidLoad() {
        super.viewDidLoad()         
    }
    @IBAction func SaveContact(_ sender: Any) {
        let entityDescription = NSEntityDescription.entity(forEntityName: "Contacts",in: managedObjectContext)

        let contact = Contacts(entity: entityDescription!,insertInto: managedObjectContext) // Error: Use of unresolved identifier 'Contacts'
    }
    @IBAction func Findcontact(_ sender: Any) {
    }
   }
+4
source share
1 answer

Here's how you set up Core Data in Xcode 8: Entity Information Example

You have 3 options:

  • Manual / no
  • Class definition
  • Category / Extension

I think they are pretty clear. Anyway, what you probably want here is a class definition.

+1
source

Source: https://habr.com/ru/post/1664514/


All Articles