Swift Regex Tutorial: Getting Started | Kodeco

Master the pattern-matching superpowers of Swift Regex. Learn to write regular expressions that are easy to understand, work with captures and try out RegexBuilder, all while making a Marvel Movies list app!


This is a companion discussion topic for the original entry at https://www.kodeco.com/36182126-swift-regex-tutorial-getting-started

Ran the app before making any changes and it crashed immediately after the orange-K splash screen loaded

Feedback given by @wtj123… β€œin the MarvelMovies file, there are 49 records. However, the result of the statement: let matches = content.matches(of: recordMatcher) in the class ProductionsDataProvider only has 39 matches. Can you explain the difference between them?”

Hello @gdelarosa,
This is actually a bug in the project that we missed :frowning:

The rows that were missed are the ones with - for the IMDB rating field. The reference types specified for the URL and the rating field are not set as optionals. When the transform in the TryCatch finds a nil the value can’t be bound so the who record is skipped.
By changing the two references to be optionals, the count for the matches is properly 49 and the missing records are showing.

let urlFieldRef = Reference(URL?.self)
let imdbRatingFieldRef = Reference(Float?.self)

Thanks for the response @ehabamer! I appreciate it. :smile: