|
Finish until checkpoint 3. I just use if, else if, else and all work fine. Now I want to try to use switch case solution... anyone have idea how to do this? Thank you |
|
This code below did not work.
error: expression pattern of type "BOOL" cannot match values of type "INT" |
|
The error is clear. But you'll need a few more sessions to get used to trouble shooting. Let's help! If you hold your option key down, and click on j, XCode will tell you that j is of type Int. Yeah, it's an integer.
Now add this line just before the Now hold the option key down and click on the variable What does XCode reveal? What type is Now you see why the compiler is not happy. You are providing an integer to the switch statement. But within the switch statement you are trying to compare j to a boolean value. You cannot compare integers to booleans! Case solved. PS: Whilst learning Swift use what ever variable names you wish. However, and hear me out on this, I think you lose the big picture when you use single letter names for variables. For example, had you named the variable
One might argue that this is more readable. Plus it might have clued you in that you are comparing an Integer (targetInteger) to a boolean (targetInteger.isMultiple(of:) returns either |
|
I did checkpoint 3 two ways:
|
|
Thank you, this give me idea to do my switch case in checkpoint 3. This is how I did it.
|
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.