Let say you have an enum:
typedef enum {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
} DayOfWeek;
when writing a switch statement, a Xcode is trying to help with switch statement snippet:
and then:
great, but I need to list all enums:
DayOfWeek day = ...; // a day of week
switch (day) {
case Sunday:
break;
case Monday:
break;
case Tuesday:
break;
case Wednesday:
break;
case Thursday:
break;
case Friday:
break;
case Saturday:
break;
default:
break;
}
Unfortunately, have to do it manually :( Is there any known snippet to populate all cases? Of course I saw some answers 3 years old states that it is impossible, but maybe something changed since that time? Any ideas?
Use Editor
> Refactor
> Add Missing Switch Cases
Preferences
by pressing [command]
+ [,]
in Xcode.Key Bindings
tab and set a shortcut for the command Refactor > Add Missing Switch Cases
.
switch
letters.
Saw your question and decided to build an Xcode plugin that does exactly that.
Check it out: https://github.com/stefanceriu/SCXcodeSwitchExpander
in Xcode 10 do the following
switch...case
template and set your enum type instead of self
so that xcode understands what it should autocompleteswitch
and go to menu > editor > refactor > expand switch cases
This is what you will get as result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With