title: JSON Array and CoreData in populating TableView
body: <p>Sorry for inconvenience, I am iOS-Beginner and have a problem... </p>
  
  <p>I have a JSON, CoreData and TableView, JSON fetched from web and saving in Documents-Folder. After that, some values from JSON saves in CoreData and TableView must be populated with it. F.E. we take an event_title..</p>
  
  <p>I have a controller:</p>
  
  <pre><code>import Foundation
  import UIKit
  import CoreLocation
  import CoreData
  
  class QuestListViewController: UIViewController, UITableViewDataSource,UITableViewDelegate {
  
  let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
  
  let eventscd = [Events]()
  
  @IBOutlet weak var questsTabBarItem: UITabBarItem!
  
  var questCode : String = ""
  
  var numberofcells:Int = 0
  
  @IBOutlet weak var tableView: UITableView!
  
  var numbers:[String] = []
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      let entity = NSEntityDescription.entityForName("Events", inManagedObjectContext: managedObjectContext!)
  
      let events = Events(entity: entity!, insertIntoManagedObjectContext: managedObjectContext)
  
      var error: NSError?
      var jsonError:NSError?
      let jsonBundle = NSBundle.mainBundle()
      let jsonFolder = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]as! String
      let jsonPath = jsonFolder.stringByAppendingPathComponent("\(self.questCode).json")
  
      if let data = NSData(contentsOfFile:jsonPath, options:NSDataReadingOptions.DataReadingUncached, error:&amp;jsonError) {
  
          let stringData = NSString(data: data, encoding: NSUTF8StringEncoding)
  
          let jsonDict : NSDictionary? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &amp;jsonError) as? NSDictionary
  
          if let err = jsonError {
              println("error parsing json")
          }
  
          if let jsonDictionary = jsonDict {
              println("json parsed successfully")
  
              let json_data = JSON(jsonDictionary).arrayValue
  
              let id = jsonDictionary["id"]!.stringValue
              let version: AnyObject = jsonDictionary["version"]!
              let title: AnyObject = jsonDictionary["title"]!
              let description: AnyObject = jsonDictionary["description"]!
              let events_json = jsonDictionary["events"] as! NSArray
              let eventNumber: NSNumber = jsonDictionary["events"]!.count as NSNumber
              self.numberofcells = events_json.count
  
          }
  
      }
  
  
      // Do any additional setup after loading the view, typically from a nib.
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  // MARK: - Table view data source
  func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
      tableView.deselectRowAtIndexPath(indexPath, animated: true)
  
      let row = indexPath.row
  
  }
  
  // MARK: - Set number of rows
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return self.numberofcells
  }
  
  // MARK: - Create cell
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
      cell.backgroundColor = UIColor.clearColor()
      cell.backgroundView = UIView.new()
      cell.selectedBackgroundView = UIView.new()
  
      var imageView = UIImageView(frame: CGRectMake(10, 10, cell.frame.width - 0.3, cell.frame.height - 0.3))
      let image = UIImage(named: "event_list_cell.png")
      imageView.image = image
      cell.backgroundView = UIView()
      cell.backgroundView!.addSubview(imageView)
      var row = indexPath.row
      let eventsc = eventscd[indexPath.row]  /////HERE IS FATAL BREAKPOINT
  
  //        cell.textLabel?.text = eventTable[row] as? String
      cell.textLabel?.text = eventsc.valueForKey("event_title")![row] as? String
  
      return cell
  }
  
  }
  </code></pre>
  
  <p>A class for Events:
      import Foundation
      import CoreData</p>
  
  <pre><code>@objc(Events) class Events: NSManagedObject {
  
      @NSManaged var title: String
      @NSManaged var event_title: String
  
  }
  </code></pre>
  
  <p>And a CoreMap:
  <a href="http://i.imgur.com/5iKwAyn.png" rel="nofollow">http://i.imgur.com/5iKwAyn.png</a></p>
  
  <p>And have an error: </p>
  
  <pre><code>On line with "let eventsc = eventscd[indexPath.row]" in Controller
  Output: "fatal error: Array index out of range"
  </code></pre>
  
  <p>Where I am wrong?</p>