This repo helps you use Enum in Swfit way.
Create A Enum Type
const Direction = ;
Now, you get a new type:
Direction, which contains four cases:
You can directly use a case by
Direction.North, or invoke it with
Direction.North(). You can pass associated values in(optionally).
Enum.type() to get the type of the case.
Direction.types to get all cases types.
// Direction is an Enum type.const myDirection = DirectionNorth;// it will log out 'North'
Use with associated values
addCase to add a plain case, or
addCaseWithAssociatedValues to add a case with values.
const AsyncState =;
Now you get a
AsyncState, it will give you 3 function
You can call the function with associated values you want to put in.
const Loading Succeed Failed = AsyncState;let state = ;axios
If the request succeed, you can put the resp in
Succeed case, and get that value via
If the request failed, you use a
Failed to represent that case, and retrieve the error using