Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

unexpectedly found nil while unwrapping an Optional value

jarvjarv Posts: 210Registered Users @ @
Please help, I get the following error:
fatal error: unexpectedly found nil while unwrapping an Optional value

import UIKit
import Alamofire
import SwiftyJSON

class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

    @IBOutlet weak var collectionView: UICollectionView!
    var town : NSArray!
    var delegate : AppDelegate?
    override func viewDidLoad() {
        Alamofire.request(.GET, "
;).responseJSON { (response) -> Void in if let value = response.result.value { let json = JSON(value) //If json is .Dictionary for (key: _, subJson: JSON) in json { = JSON["town"] as! NSArray print( } } } // 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. } func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! TownCollectionViewCell cell.townLabel?.text =[indexPath.row] as? String return cell } func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { self.performSegueWithIdentifier("showTown", sender: self) } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "showTown"{ let indexPaths = self.collectionView!.indexPathsForSelectedItems()! let indexPath = indexPaths[0] as NSIndexPath let vc = segue.destinationViewController as! TownController vc.title =[indexPath.row] as? String } } }


Sign In or Register to comment.