1

I have the following nested structure:

public struct Session {
    public enum Type: Int {
        FirstLaunch = 0, NotRegistered, LoggedOut, LoggedIn
    }
}

It's very simple, very barebones. However when I try to access FirstLaunch for example, Xcode throws the following error:

'Session.Type.Type' does not have a member named 'FirstLaunch'

Anyone have any idea what's going on?

1
  • 1
    This is a bad error message and probably worth an official bug report. Commented Aug 17, 2014 at 7:18

2 Answers 2

5

Type is a reserved word in Swift. You can escape it by surrounding it with back ticks.

“If you need to give a constant or variable the same name as a reserved Swift keyword, you can do so by surrounding the keyword with back ticks (`) when using it as a name. However, you should avoid using keywords as names unless you have absolutely no choice.”

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l

Sign up to request clarification or add additional context in comments.

2 Comments

THIS. Another reason why to not give generic names to your times.
Take away here is "you should avoid using keywords as names unless you have absolutely no choice."
1

I figured it out. Looks like you can't use the word Type to name any structure. It's probably a reserved keyword or something of that nature.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.