|
Wondering if anyone can spot why the following doesn't correctly identify all positive search results:
For example, if searchTerm =
|
|
The way you have your check set up, if one of the books does not match, all previous matches get cleared out of your result array:
So let's walk it through...
You don't need the You can easily see what's going on if you stick some |
|
@rooster has the right answer! May I add a comment? You have the start of a
Consider moving Book related logic to your
By encapsulating business logic in your
Homework problem: How might you create a I agree with @rooster. Think of better names for both Keep coding! |
|
Heck, go even further and pull out the array-searching logic into an extension:
Then you can just do this to get an array of
|
|
Thanks for the assists, @roosterboy & @Obelix! I've been able to fix the logic and simplify the code (including moving I'll hold off applying the |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.