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 Enums and their Methods Initializer

Freddie Teague
Freddie Teague
13,808 Points

I am getting an error as I am trying to init in playground.

enum Day: Int {
    case Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday

    init() {
        self = .Monday
    }

    func daysTilWeekend() -> Int {
        return Day.Saturday.rawValue - self.rawValue
     }
}
var today = Day()
today.rawValue

Here is my code that I am following along with on the video to learn about initializers and I am getting an error of: "Cannot invoke initializer for the type 'Day' with no arguments. Any ideas?

Freddie Teague
Freddie Teague
13,808 Points

I am using the latest version of xCode that is still in β€œbeta” status...possibly a bug?

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

I am using the latest version of xCode that is still in β€œbeta” status...possibly a bug?

Yes, it's possible. Apple is keep making alot of enhancement and change to the Swift language.

I even copy/paste your code to my Playground, and it's fine. I'm using final release of Xcode, so the version is behind your beta release.

Imgur