Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

is it better practice to use switch statements or arrays?

I am attempting to my own quiz app in swift 3 and was wondering, is it better practice to use switch statements or arrays for the questions/answers? Sometimes its hard to tell what is the best practice since many times there are more than 1 way to code things...

1 Answer

Well... In swift arrays (which are data structures) and switching (which is control flow) are very different, but if you are in any program deciding which way you should use to write a program, decide with these in mind:

Keep in mind that these are in order. Ones on the top are more important to satisfy!

  • DRY (Don't Repeat Yourself, the most important!!)
  • Readable (also very important!!)
  • Fast and high performance while running
  • Simple, easy to understand
  • Short