Fatal error when func is called with scene kit and swift IOS
<p>I have a little problem, after a download i want to launch a function but i have this fatal error :</p>

<blockquote>
  <p>fatal error: unexpectedly found nil while unwrapping an Optional value</p>
</blockquote>

<p>when my download is end i call a function telechargementOK()</p>

<pre><code>func telechargementOK() {
    println("Telechargement ok")
    renduScene()
}

func renduScene() {
    println("Chargement de la vue 3D")

    let scnView2 = self.view3D as SCNView
    scnView2.scene = SCNScene(named: "art.scnassets/MASTER.dae")
    scnView2.autoenablesDefaultLighting = true
    scnView2.allowsCameraControl = true


    let filemgr = NSFileManager.defaultManager()
    var documentsDirectoryURL = filemgr.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false, error: nil)
    documentsDirectoryURL = documentsDirectoryURL?.URLByAppendingPathComponent("/Modules.scnassets/Module-01.dae")
    let module1Scene = SCNScene(URL: documentsDirectoryURL!, options: nil, error: nil)
    //println("\(module1Scene)")
    scnViewModule1.scene = module1Scene
    module1 = scnViewModule1.scene?.rootNode.childNodeWithName("Module-01", recursively: true)
    //println("\(module1)")
    scnView2.scene?.rootNode.addChildNode(module1!)

    tapRecognizer.numberOfTapsRequired = 1
    tapRecognizer.numberOfTouchesRequired = 1
    tapRecognizer.addTarget(self, action: "sceneTapped:")
    scnView2.addGestureRecognizer(tapRecognizer)
}
</code></pre>

<p>When i take this code to viewDidLoad() all is ok...</p>

<p>Stoun</p>

<p>UPDATE :</p>

<p>this is my complete code :</p>

<pre><code>//
//  ViewController.swift
//  Gare et Connexions
//
//  Created by Stoun on 25/02/2016.
//  Copyright (c) 2016 Stoun. All rights reserved.
//

import UIKit
import SceneKit
import Foundation

class ViewController: UIViewController {

@IBOutlet weak var view3D : UIView?

let tapRecognizer = UITapGestureRecognizer()

var scnView3 = SCNView()
var scnViewModule1 = SCNView()
var module1 = SCNNode?()

var connexion = NSString()


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    //1 - on va regarder pour copier les modules dans un dossier du dossier documents de l'appli
    let filemgr = NSFileManager.defaultManager()
    var error : NSError?
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
    //test dossier
    // path to documents directory
    let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as String
    // create the custom folder path
    let myCustomDataDirectoryPath = documentDirectoryPath.stringByAppendingPathComponent("/Modules.scnassets")
    // check if directory does not exist
    if NSFileManager.defaultManager().fileExistsAtPath(myCustomDataDirectoryPath) == false {

        // create the directory
        var createDirectoryError: NSError? = nil
        NSFileManager.defaultManager().createDirectoryAtPath(myCustomDataDirectoryPath, withIntermediateDirectories: false, attributes: nil, error: &amp;createDirectoryError)

        // handle the error, you may call an exception
        if createDirectoryError != nil {
            println("Handle directory creation error...")
        }

    }


    //2-on teste la connexion
    let status = Reach.connectionStatus()
    switch status {
    case .Unknown, .Offline:
        println("Not connected")
        connexion = "NON"
    case .Online(.WWAN):
        println("Connected via WWAN")
        connexion = "3G"
    case .Online(.WiFi):
        println("Connected via WiFi")
        connexion = "WIFI"
    }

    //3 - on télécharge ou pas
    if ((connexion == "NON") || (connexion == "3G")){
        //on telecharge pas, on mets une alerte pour dire que les modules ne sont peut-être pas à jour
        // create the alert
        let alert = UIAlertController(title: "MESSAGE IMPORTANT", message: "Vous n'êtes pas connecté à internet ou vous avez une connexion en 3G. Les modules ne sont peut-être pas à jour. Merci de vous connecter via un réseau wifi pour mettre à jour les modules.", preferredStyle: UIAlertControllerStyle.Alert)
        // add an action (button)
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
        // show the alert
        dispatch_async(dispatch_get_main_queue(), {
            self.presentViewController(alert, animated: true, completion: nil)
        })
        renduScene()
    }
    else if (connexion == "WIFI"){
        //on télécharge
        var URL = NSURL(string: "http://urbis-guadeloupe.fr/stoun/3Dgare/Module-01-opt.dae.zip")
        //var URL = NSURL(string: "http://urbis-guadeloupe.fr/stoun/3Dgare/B00001.png")
        Downloader.load(URL!)
        //renduScene()

        scnView3 = self.view3D as SCNView

        //on vois pour la suite - afficher la 3D
        //let scnView = self.view3D as SCNView
        scnView3.scene = SCNScene(named: "art.scnassets/MASTER.dae")
        scnView3.autoenablesDefaultLighting = true
        scnView3.allowsCameraControl = true

        //scnViewModule1 = self.view3D as SCNView
        //test chargement dossier document
        /*if ((connexion == "NON") || (connexion == "3G")){
        var documentsDirectoryURL = filemgr.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false, error: nil)
        documentsDirectoryURL = documentsDirectoryURL?.URLByAppendingPathComponent("/Modules.scnassets/Module-01-opt.dae")
        let module1Scene = SCNScene(URL: documentsDirectoryURL!, options: nil, error: nil)
        //println("\(module1Scene)")
        scnViewModule1.scene = module1Scene
        module1 = scnViewModule1.scene?.rootNode.childNodeWithName("Module-01", recursively: true)
        //println("\(module1)")
        scnView3.scene?.rootNode.addChildNode(module1!)
        /*let module1Scene = SCNScene(named: "art.scnassets/Module-01.dae")
        scnViewModule1.scene = module1Scene
        module1 = scnViewModule1.scene?.rootNode.childNodeWithName("Module-01", recursively: true)
        scnView.scene?.rootNode.addChildNode(module1!)*/
        }*/
        tapRecognizer.numberOfTapsRequired = 1
        tapRecognizer.numberOfTouchesRequired = 1
        tapRecognizer.addTarget(self, action: "sceneTapped:")
        scnView3.addGestureRecognizer(tapRecognizer)
    }

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func sceneTapped(recognizer: UITapGestureRecognizer) {

    let scnView = self.view3D as SCNView

    let location = recognizer.locationInView(scnView)

    let hitResults = scnView.hitTest(location, options: nil)
    if hitResults?.count &gt; 0 {
        let result = hitResults![0] as SCNHitTestResult
        let node = result.node
        println("Node select : \(result.node.name)")
        if (result.node.name == "Module-01"){
            println("Module-01")
        }
    }
}

func telechargementOK(){

    println("Telechargement ok")
    renduScene()

}

func renduScene() {
    println("Chargement de la vue 3D")

    if let scnView2 = self.view3D as? SCNView{
        println(1)

    scnView2.scene = SCNScene(named: "art.scnassets/MASTER.dae")
    scnView2.autoenablesDefaultLighting = true
    scnView2.allowsCameraControl = true

    let filemgr = NSFileManager.defaultManager()
    var documentsDirectoryURL = filemgr.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false, error: nil)
    documentsDirectoryURL = documentsDirectoryURL?.URLByAppendingPathComponent("/Modules.scnassets/Module-01-opt.dae")
    let module1Scene = SCNScene(URL: documentsDirectoryURL!, options: nil, error: nil)
    println("\(module1Scene)")
    scnViewModule1.scene = module1Scene
    module1 = scnViewModule1.scene?.rootNode.childNodeWithName("Module-01", recursively: true)
    println("\(module1)")
    scnView2.scene?.rootNode.addChildNode(module1!)

    tapRecognizer.numberOfTapsRequired = 1
    tapRecognizer.numberOfTouchesRequired = 1
    tapRecognizer.addTarget(self, action: "sceneTapped:")
    scnView2.addGestureRecognizer(tapRecognizer)
    }
    else {
        println(2)
        let filemgr = NSFileManager.defaultManager()
        var documentsDirectoryURL = filemgr.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false, error: nil)
        documentsDirectoryURL = documentsDirectoryURL?.URLByAppendingPathComponent("/Modules.scnassets/Module-01-opt.dae")
        let module1Scene = SCNScene(URL: documentsDirectoryURL!, options: nil, error: nil)
        println("\(module1Scene)")
        scnViewModule1.scene = module1Scene
        module1 = scnViewModule1.scene?.rootNode.childNodeWithName("Module-01", recursively: true)
        println("\(module1)")
        scnView3.scene?.rootNode.addChildNode(module1!)

    }
}

}
</code></pre>

<p>When the device is connected to internet this is the log :</p>

<pre><code>Connected via WiFi
Success: 200
Copy from serveur successful
Remove ZIP successful
Remove dae from folder successful
Copy dae in folder successful
Remove dae from folder successful
Telechargement ok
Chargement de la vue 3D
2
Optional(&lt;SCNScene: 0x1780e1c80&gt;)
Optional(&lt;SCNNode: 0x100b11a20 'Module-01' | 4 children&gt;)
</code></pre>

<p>but SCNNode Module-01 is not on the view</p>

<p>when the device is offline the log :</p>

<pre><code>Not connected
Chargement de la vue 3D
1
Optional(&lt;SCNScene: 0x1780f7c80&gt;)
Optional(&lt;SCNNode: 0x13fe271b0 'Module-01' | 4 children&gt;)
</code></pre>

<p>all is on the view
i don't understand why when the device is online the node is not on the view !</p>

<p>Stoun</p>