Pick the fix
You keep passing a user ID where an order ID is expected. Both are UUIDs. Which prevents it at compile time?
Hint 1 of 1
Does a typealias create a new type?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A struct ID<Tag>: Hashable { let raw: UUID } with ID<User> and ID<Order>
Correct. Different tags make different types.
Why not the others?
- B
typealias UserID = UUIDandtypealias OrderID = UUID. Typealiases are just new names; the compiler treats them as the same type. - C Naming parameters clearly. It helps readers, but nothing stops a mix-up.
- D Subclass UUID. UUID is a struct; you can't subclass it.