Swift Enum errors

I’m working on converting an existing Swift project, and running across a few issues with enums…

This first one wouldn’t compile with implied String values, but insisted that I write out explicit values. Simple fix, but a bit annoying coming from Xcode’s Swift compiler:

I have no clue what this is supposed to mean…

I get these errors in the build log (/Users/user/ directory obfuscated):

    ~/Documents/24by7/JSONData.swift(23,10): error E1: identifier expected, got "Type"
    ~/Documents/24by7/JSONData.swift(23,10): error E375: One of "case", "func", "subscript", "var", "typealias", "init" expected, got "Type"
    ~/Documents/24by7/JSONData.swift(23,10): error E1: closing bracket expected, got "Type"
    ~/Documents/24by7/JSONData.swift(23,10): error E504: Semicolon (;) required to separate two statements on the same line
    ~/Documents/24by7/JSONData.swift(23,10): error E477: Declaration expected
    ~/Documents/24by7/JSONData.swift(23,10): error E1: identifier expected, got "Type"
    ~/Documents/24by7/JSONData.swift(23,10): error E375: One of "case", "func", "subscript", "var", "typealias", "init" expected, got "Type"
    ~/Documents/24by7/JSONData.swift(23,10): error E1: closing bracket expected, got "Type"
    ~/Documents/24by7/JSONData.swift(23,10): error E504: Semicolon (;) required to separate two statements on the same line
    ~/Documents/24by7/JSONData.swift(23,10): error E477: Declaration expected

Assuming it’s a big of some kind…?

Type is a keyword. You need to escape it, if you want to use it as an identifier. I’ll look at whether we can improve the error for this case.

Thanks, logged as bugs://75159

I’m not quite sure what this means. Can you give en example of the code tha did not compile and what you had to change?

Got it (the implied string values). Fixed for the next build.

bugs://75159 got closed with status fixed.

It looks like Carlo got it, but basically I defined the enum cases without specifying the associated raw values. In Xcode, I was used to these being implicitly assigned, even with Strings, but it didn’t do that. Like I said, not a big deal, just really annoying…

Thanks for the hint on Type though. I’ll try escaping it when I get back home. If I may ask, where else is “Type” used as a keyword?

It’s used such as

let t = String.Type

to get the meta type of a type.

Oh. Well, that works then. I guess I could escape it in the enum. Funny how Xcode’s llvm used mine over its keyword… I’ve never tried, come to think of it, but I wonder how I’d get the metatype back there…

Something new to try! :smiley:

So Xcode has no problem with Type in this context? If so,Mae should fix that too, make it a conditional keyword. (Also, iirc this whole type syntax is changing for 3.0 anyways).

Logged as bugs://i63167.

bugs://i63167 was closed as fixed.