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 Enumerations and Optionals in Swift Introduction to Enumerations Enum Methods

Jesse Gay
seal-mask
.a{fill-rule:evenodd;}techdegree
Jesse Gay
Full Stack JavaScript Techdegree Student 14,045 Points

To make this code challenge work in Xcode, I had to import UIKit.

To make part 2 of this code challenge work in Xcode, I had to import UIKit. However, the code challenge in the Treehouse App didn't require me to import it. Why? Were we to assume that it had already been imported? https://teamtreehouse.com/library/enumerations-and-optionals-in-swift/introduction-to-enumerations/enum-methods

mrtroy
mrtroy
8,069 Points

This gotcha cost me aggravation also. The hard part was that the output.html was just blank with no error.

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Yes, you were to assume that UIKit was imported for you. These challenges tend to be very literal. In fact, if you try and import UIKit inside the challenge, it will fail with a compiler error.

:bulb: It is always a good idea when doing these to try not to do anything that is not explicitly asked for by the challenge. Even if functional outside the challenge, it can cause it to fail. Obviously, you would be required to import it in Xcode as UIButton is a part of UIKit.

Hope this helps! :sparkles:

Jesse Gay
seal-mask
.a{fill-rule:evenodd;}techdegree
Jesse Gay
Full Stack JavaScript Techdegree Student 14,045 Points

Thanks Jennifer! Good tips. I wonder if it might not help students if the code challenge included a reminder that UIKit has been imported. We've only had to manually import a few things so far, so it might help reinforce the idea of importing in general (when we need to do it and why.)

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Jesse Gay you could be correct. They could possibly even include a comment at the top of the code like so:

// import UIKit would normally appear here but has been imported for you

I would suggest that you submit it as a suggestion to the teaching team or other Treehouse staff.

Another tip for later on: If you think you're overthinking the challenge, you're likely correct :smiley: