Compile error in swift when accessing enum inside a Constant class -
i have code won't compile. idea want keep global constant class.
viewcontroller.swift:
var user = [string: string]() user[cuser.attribute.type] = usertypeswitch.on ? cuser.type.rider.rawvalue : cuser.type.rider.rawvalue
cuser.swift
class cuser { enum type: string { case rider case driver } class attribute { static let type = "type" } }
error message this: "type 'cuser.type' has no member 'rider'"
but when enclose enum type type in dummy class compiles fine. such that:
user[cuser.attribute.type] = usertypeswitch.on ? cuser.dummy.type.rider.rawvalue : cuser.dummy.type.rider.rawvalue
you cannot use type
name inside class because it's metatype type.
a metatype type refers type of type, including class types, structure types, enumeration types, , protocol types.
the metatype of class, structure, or enumeration type name of type followed .type. metatype of protocol type—not concrete type conforms protocol @ runtime—is name of protocol followed .protocol. example, metatype of class type someclass someclass.type , metatype of protocol someprotocol someprotocol.protocol.
just rename it.
Comments
Post a Comment