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!