How do I use reserved keyword `Type`?

I know, It doesn’t make sense. but I have no choice.

let type = ReservedKeyword.`Type`(rawValue: 1)

public class ReservedKeyword {
    public enum `Type`: Int, Codable {
        case zero = 0
        case one = 1
        case two = 2
        case three = 3

It seems like a bug to me if it's not working with backticks. Perhaps you can call it something else, like Kind? TSPL says avoid using keywords as names unless you have absolutely no choice.

1 Like

@suyashsrijan thanks.
finally, I found this(It works)

let type = ReservedKeyword.self.`Type`(rawValue: 1)

I think it does make sense, but even though it can't be done directly, you can typealias to use the workaround standard.

typealias ReservedKeywordType = ReservedKeyword.`Type`
let type = ReservedKeywordType(rawValue: 1)

I got it. good workaround.

1 Like
Terms of Service

Privacy Policy

Cookie Policy