🤯 (0, 0) matches four cases in this Swift switch. Only one runs. Which?
🧩 switch (x, y) turns two values into a tuple
🎯 case (0, 0) is one point
➖ case (_, 0) is the whole x-axis: _ matches anything
📦 case (-2...2, -2...2) is a box
🧵
🤯 (0, 0) matches four cases in this Swift switch. Only one runs. Which? 🧩 switch (x, y) turns two values into a tuple 🎯 case (0, 0) is one point ➖ case (_, 0) is the whole x-axis: _ matches anything 📦 case (-2...2, -2...2) is a box 🧵
0 views
Published on 01/12/2026 06:19
1:12
🤯 (0, 0) matches four cases in this Swift switch. Only one runs. Which?
🧩 switch (x, y) turns two values into a tuple
🎯 case (0, 0) is one point
➖ case (_, 0) is the whole x-axis: _ matches anything
📦 case (-2...2, -2...2) is a box
🧵
🚨 Put (_, 0) before (0, 0) and "origin" never runs
🙈 And the compiler stays silent
💡 Rule: most specific pattern first, catch-all last
🎓 Want to learn more? Check Mastering Swift - From Beginner to Advanced 👇
www.udemy.com/course/swift...