//

//  ViewController.swift

//  lastcoredata

//

//  Created by Shamshir Anees on 03/11/16.

//  Copyright © 2016 Shamshir Anees. All rights reserved.

//



import UIKit

import CoreData



class ViewController: UIViewController {

    

    @IBOutlet var labelmain: UILabel!

    

    @IBOutlet var textfi: UITextField!

var people: [NSManagedObject] = []

    override func viewDidLoad() {

        super.viewDidLoad()

        

    }



    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

           }



    func save(name: String) {

             guard let appDelegate =

            UIApplication.shared.delegate as? AppDelegate else {

                return

        }

        

                let managedContext =

            appDelegate.persistentContainer.viewContext

        



        let entity =

            NSEntityDescription.entity(forEntityName: "Person",

                                       in: managedContext)!

        

        let person = NSManagedObject(entity: entity,

                                     insertInto: managedContext)

        

      

        

        person.setValue(name, forKeyPath: "name")

        

        // 4

        do {

            try managedContext.save()

            people.append(person)

        } catch let error as NSError {

            print("Could not save. \(error), \(error.userInfo)")

        }

    }

    

    @IBAction func savebutton(_ sender: AnyObject) {

        people.removeAll()

        let nameToSave = textfi.text

        self.save(name:nameToSave!)

    

        

               print(people.count)



    }

    override func viewWillAppear(_ animated: Bool) {

        super.viewWillAppear(animated)

        

        //1

        guard let appDelegate =

            UIApplication.shared.delegate as? AppDelegate else {

                return

        }

        

        let managedContext =

            appDelegate.persistentContainer.viewContext

        

        

        //2

        let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "Person")

        

        //3

        do {

            people = try managedContext.fetch(fetchRequest)

        } catch let error as NSError {

            print("Could not fetch. \(error), \(error.userInfo)")

        }

    }



  

}



This is my code
am new to iOS app development
i want to fetch data and display it to my label
pls anybody help