can you pass an enum as a parameter to a function swift
func justAnExample<T : RawRepresentable>(_ enumType: T.Type) where T.RawValue == Int {
// Note that an explicit use of init is required when creating an instance from a
// metatype. We're also using a guard, as `init?(rawValue:)` is failable.
guard let val = enumType.init(rawValue: 0) else { return }
print("description: \(val)")
}
justAnExample(Foo.self) // prints: "description: Hello Foo"
justAnExample(Bar.self) // prints: "description: Hello Bar"
Also in Swift:
- hide status bar ios
- swift access appdelegate from viewcontroller
- swift array to string
- swift push view controller
- Failure Reason: SecurityUser Info: {DVTRadarComponentKey = 855031;RawLLDBErrorMessage = Security
- spacing in uitextfield
- power swift
- ui alert swift yes no
- swift 5 only the day number from date
- swift find difference between two arrays
- swift initialize a view
- change the title of a button using Swift
- foreach swiftui object
- swift increase int value
- swift play audio file
- swift initialize array with size
- how to know when text changed textfield swiftui
- stack view xcode
- how to set the center in view in swift
- navigationviewcontroller setviewcontrollers swift
- check if nan swift
- index string swift
- create alert in swift
- swift how to call a function