How to pass the value of inside a function a global variable in a class in Swift?

I would like to store the value inside the function to the global variable inside the class. I believe the problem might be with optionals. Because it seems that the value is just stored inside the function but not outside. I would appreciate any kind of help :)

Here is the code:

class PinterestCell: UICollectionViewCell {
    //I want to store the value inside the function here ..
    var imageViewHeightLayoutConstraint: NSLayoutConstraint

    override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
            if let attributes = layoutAttributes as? PinterestLayoutAttributes {
                //How can I pass the following value to the property imageViewHeightLAyoutConstraint
                    imageViewHeightLayoutConstraint.constant = attributes.imageHeight

Read more here:

Content Attribution

This content was originally published by alan bahena at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: