Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build an Interactive Story App with Swift Refactoring Our Code Immediately Executing Anonymous Functions

Haifa Bassam
Haifa Bassam
10,333 Points

Error: Expression is not assignable: function call returns immutable value

when I write this code:

let storyLabel = UILabel() = {
    let label = UILabel()
    label.translatesAutoresizingMaskIntoConstraints = false
    label.numberOfLines = 0
    return label

I get an error:

Expression is not assignable: function call returns immutable value

Any clues why?

2 Answers

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

Your issue is on the first line:

let storyLabel = UILabel() = {

It looks like you are trying to set the type of the storyLabel constant to UILabel. Instead you are assigning the constant to a new UILabel instance and then trying to assign the result of the UILabel initializer to the closure result.

To set the type pf the constant, you should use this:

let storyLabel: UILabel = {