|
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 |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
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.