call value variable from outside function in swift
I have a problems to call a variable in class, from outside function. 
Swift gives me the following error: Use of unresolved identifier 'imageFilename'
How I can solve it? How should I get the value of the Filename variable?
My code:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    if (collectionView == self.collectionView1)
    {
        let cell : FeaturedCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(self.reuseIdentifierFeatured, forIndexPath: indexPath) as! FeaturedCollectionViewCell

        let imgURL: NSURL = NSURL(string: "http://localhost:9001/feature-0.jpg")!
        let request: NSURLRequest = NSURLRequest(URL: imgURL)

        let session = NSURLSession.sharedSession()
        let task = session.dataTaskWithRequest(request){
            (data, response, error) -> Void in

            if (error == nil && data != nil)
            {
                func display_image()
                {
                   let imageFilename = UIImage(data: data!)
                }
                dispatch_async(dispatch_get_main_queue(), display_image)
            }
        }

        task.resume()

        cell.featuredImage.image = UIImage(named: imageFilename)
        return cell
    }
}

Image capture link

The possible issue could be that imageFileName is inside a different scope, so it actually removed before reaching to the part where you're trying to use it. Declare it as var outside of the if scope.

The scope of imageFileName is the function display_image in which it is declared, it is not visible outside that if. The problem is not the access of a variable in a class, your custom cell class doesn't seem to declare a variable named imageFileName
Edit
Why don't you set the image inside the completion closure?:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    if (collectionView == self.collectionView1) {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(self.reuseIdentifierFeatured, forIndexPath: indexPath) as! FeaturedCollectionViewCell

        let imgURL: NSURL = NSURL(string: "http://localhost:9001/feature-0.jpg")!
        let request: NSURLRequest = NSURLRequest(URL: imgURL)

        let session = NSURLSession.sharedSession()
        let task = session.dataTaskWithRequest(request) {
            (data, response, error) -> Void in

            if (error == nil && data != nil) {
                dispatch_async(dispatch_get_main_queue()) {
                    cell.featuredImage.image = UIImage(data: data!)
                }
            }
        }
        task.resume()

        return cell
    }
}

Be aware that due to the fact that asynchronous request may complete in an undefined order and cell reuse, you can end up with incorrect images for cells, you could save the image url in the cell and check if it is the same as the one captured in the closure when the the closure completes.

OK. And I can declare a variable within cell?

How about if you declare the variable outside of the function and inside of the function you set the value. Then you have access to the variable and its value.
Your Problem is definetly that you can not access the variable, because it is just know inside of the function.
Code:
try it like this...
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {



if (collectionView == self.collectionView1)
{
    let cell : FeaturedCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(self.reuseIdentifierFeatured, forIndexPath: indexPath) as! FeaturedCollectionViewCell

    var imageFilename: UIImage


    let imgURL: NSURL = NSURL(string: "http://localhost:9001/feature-0.jpg")!
    let request: NSURLRequest = NSURLRequest(URL: imgURL)

    let session = NSURLSession.sharedSession()
    let task = session.dataTaskWithRequest(request){
        (data, response, error) -> Void in




        if (error == nil && data != nil)
        {
            func display_image()
            {
               imageFilename = UIImage(data: data!)
            }

            dispatch_async(dispatch_get_main_queue(), display_image)
        }


    }

    task.resume()

    cell.featuredImage.image = UIImage(named: imageFilename)
    return cell
}
}

Write me if this worked for you.

Thanks man! Now is visible var :) but say this error:
Cannot convert value of type 'UIImage' to expected argument type 'String' in this line code: cell.featuredImage.image = UIImage(named: imageFilename)

Ok, this error seems to be pretty easy. You are trying to set a value which is of type string to a variable which is of type UIImage. cell.featuredImage.image of which type is that?

I think it is a better idea to open it in a new thread, otherwise this is very hard to understand... You can comment here under which thread you opened it and I will answer it again?

Ok. cell.featuredImage.image is a UIImage, the original code for imageFilename was this: let  imageFilename = "feature-(indexPath.row).jpg", this image in storyboard is inside of Viewcontroller > View > Scroll View > Collection view > Featured Cell > Featured Image.

I want to change the value "feature-(indexPath.row).jpg" for URL image

What do you want to change to "feature-(indexPath.row).jpg" ?

No, i want change let  imageFilename = "feature-\(indexPath.row).jpg" to let  imageFilename = "http://www.miweb.com/images/myimage.jpg"

Sorry! I solved without UImage, only with string for url http. Thanks a lot!!
