title: How use coredata in MVC
body: <p>I can use Core Data in Functions but i can´t create in MVC, like this:</p>
  <pre><code>class addBD{
      func add(){
  
          let entityDescripition = NSEntityDescription.entityForName(&quot;Radar&quot;,inManagedObjectContext: managedObjectContext!)
          let task = Radar(entity: entityDescripition!, insertIntoManagedObjectContext: managedObjectContext)
          task.descricao = vlrDesc.text
          task.latitude = fieldLatitude.text
          task.longitude = fieldLongitude.text;
          task.velocidade = picker.selectedRowInComponent(0)
          managedObjectContext?.save(nil)
          
      }
  }
  
  import UIKit
  import CoreData
  
  class adicionarRadar: UIViewController, NSFetchedResultsControllerDelegate {
     
  func createTask() {
      
      adic.add()
  }
  </code></pre>
  <p>I have this errors:</p>
  <blockquote>
  <p>Use of unresolved identifier 'managedObjectContext'</p>
  <p>Use of unresolved identifier 'vlrDesc'</p>
  </blockquote>
  <p>... all of the variables</p>
  <hr />
  <pre><code>class addBD{
      func add(){
  
          let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
          let managedContext = appDelegate.managedObjectContext!
          
          let entityDescripition = NSEntityDescription.entityForName(&quot;Radar&quot;,inManagedObjectContext: managedContext)
          let task = Radar(entity: entityDescripition!, insertIntoManagedObjectContext: managedContext)
          task.descricao = vlrDesc.text
          task.latitude = fieldLatitude.text
          task.longitude = fieldLongitude.text;
          task.velocidade = picker.selectedRowInComponent(0)
          managedContext.save(nil)
          
      }
  }
  
  import UIKit
  import CoreData
  
  class adicionarRadar: UIViewController, NSFetchedResultsControllerDelegate {
  
      var velocidade = [&quot;40&quot;,&quot;50&quot;,&quot;70&quot;,&quot;90&quot;,&quot;100&quot;,&quot;120&quot;]
      
      var latitude:String = &quot;&quot;
      var longitude:String = &quot;&quot;
      var descrip:String = &quot;&quot;
      var velocid:NSNumber = 0.0
      var task: Radar? = nil
      var idPicker:Int = 0
      let adic = adiciona()
      
      let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
      
      @IBOutlet weak var fieldLatitude: UITextField!
      @IBOutlet weak var fieldLongitude: UITextField!
      @IBOutlet weak var picker: UIPickerView!
      @IBOutlet weak var vlrDesc: UITextField!
  
      
      @IBAction func adicionar(sender: AnyObject) {
          if task != nil {
              editTask()
          } else {
              createTask()
          }
          dismissViewController()
      }
  
  func createTask() {
      
      adic.add()
  }
  
  func editTask() {
  
      task?.descricao = vlrDesc.text
      task?.latitude = fieldLatitude.text
      task?.longitude = fieldLongitude.text
      task?.velocidade = picker.selectedRowInComponent(0)
      println(picker.selectedRowInComponent(0))
      managedObjectContext?.save(nil)
      }
  
  func dismissViewController() {
      navigationController?.popViewControllerAnimated(true)
  }
  
      func textFieldSouldReturn (textField: UITextField) -&gt; Bool{
          textField.resignFirstResponder()
          return true
      }
      
      override func touchesBegan(touches: Set&lt;NSObject&gt;, withEvent event: UIEvent) {
          self.view.endEditing(true)
      }
      
      override func viewDidLoad() {
  
          vlrDesc.text = descrip
          fieldLatitude.text = latitude
          fieldLongitude.text=longitude
          idPicker = Int(velocid)
          picker.selectRow(idPicker, inComponent: 0, animated: true)
          super.viewDidLoad()
  
          // Do any additional setup after loading the view.
      }
      
      func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -&gt; String! {
          return velocidade[row]
      }
      
      func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -&gt; Int {
          return velocidade.count
      }
      
      func numberOfComponentsInPickerView(pickerView: UIPickerView) -&gt; Int {
          return 1
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  }
  </code></pre>