error while assigning string to uilabel swift

I have two view controllers one is main ViewController in which at bottom i putted container view and that container is connected to another NewViewController which i want to show in main ViewController. I'm setting JSON data to NewViewController's label in ViewController it gives me error as fatal error : unexpectedly found nil while unwrapping an Optional value

ViewController.swift

let nvc = NewViewController()
func someFunction {
     let data = JSON as! NSDictionary
     let result = data["result"] as! NSArray
     let mytitle = result.valueForKey("name") as! NSArray
     let count = mytitle.count - 1
     for index in 0...count {
         let nameOfPlace = mytitle[index] as! String
         print(nameOfPlace) //prints all the names of places
         self.nvc.nameLabel.text = nameOfPlace //Thread 1:EXC_BAD_INSTRUCTION
     }

NewViewController.swift

@IBOutlet weak var nameLabel: UILabel!


ANSWERS:


Do not set any IBOutlet of your UIViewController before it is displayed.

The IBOutlet is probably not initialised yet. I would suggest making a string property, setting it when you initialise your UIViewController and setting that text to your UILabel in the viewDidLoad or viewWillAppear method.

Hope this helped!



 MORE:


 ? Swift TextField Issue
 ? Deinit method is never called - Swift playground
 ? Deinit method is never called - Swift playground
 ? Deinit method is never called - Swift playground
 ? Deinit method is never called - Swift playground
 ? Memory leaks in the swift playground / deinit{} not called consistently
 ? Swift Deinitialization of Globals
 ? Memory leaks in the swift playground / deinit{} not called consistently
 ? Swift: no output for println in deinit method (not using playground)
 ? Trying to pass nil but compiler keeps making me force unwrap an optional value Swift