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! While you're at it, check out some resources Treehouse students have shared here.

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 Swift Enums and Structs Structs and their Methods Review and Final Exam

McKenna Rowe
McKenna Rowe
2,930 Points

I define var Status in my struct & an Xcode error says I must add a semicolon before the (): var status: Status;()

It will not accept what the video lesson has:

struct Task {
    var description: String
    var status: Status()
       //no semicolon 
    init(description: String) {
        self.description = description
    }
}

but it will accept it if I add a semicolon after Status, like so:

struct Task {
    var description: String
   //semicolon added
    var status: Status;()

    init(description: String) {
        self.description = description
    }
}

3 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi McKenna Rowe,

The code you have above shouldn't have worked at all as it contains a syntax error since you have a rouge set of parenthesis after your semi-colon, instead you would want something like the below.

enum Status {
    case Doing, Pending, Completing
}

struct Task {
    var description: String
    var status: Status

    init(description: String) {
        self.description = description
        self.status = .Pending
    }
}

Hope that helps.

Felix Salazar
Felix Salazar
3,879 Points

If you just wanted to initialze your var status like in the video, juste change the colon ( : ) for for an equal ( = ). Lets say:

var variable = VarType()

A little remainder for this case: A colon is to define a type of a variable (or constant) and an equal sign is to assign a value to it.

Hope this helps.