I have string array of file names, which looks like this
["xBGEx.jpg", "OgJuM.jpg"]
This is images, which saved to documents directory. I try to create array of UIImages by appending full path in for look and then appending to array.
In my appDelegate I have code in didFinishLaunchingWithOptions it looks like
var paths:[AnyObject] = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
var documentsDirectory = paths[0] as? String
self.documentsRoot = documentsDirectory! + "/"
Then, when Im in controller, which I need I do the following
var slider = ["xBGEx.jpg", "OgJuM.jpg"]
var UIImageArray = [UIImage]()
for element in imgArray {
var path = "\(appDelegate.documentsRoot!)" + "\(element)"
var obj:UIImage = UIImage(contentsOfFile: path)!
UIImageArray.append(obj)
}
imageArray = UIImageArray
but when I build I have nil error in the moment of appending

What am I doing wrong ?
NSSearchPathForDirectoriesInDomainsreturns an non-optional [String], any casting and optional binding is not needed at all. Apart from that I recommend the URL related API ofNSFilemanagerand the designated methods to append path components.