Last active
October 24, 2025 07:36
-
-
Save dterekhov/94896ef6895d41a19616561be0b91519 to your computer and use it in GitHub Desktop.
Don't create small structures, use Structural types #tip #swift-api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Demonstrates that tuple type aliases with identical structures are considered equal by Swift. | |
| typealias Person = (name: String, age: Int) | |
| typealias Address = (street: String, houseNumber: Int) | |
| let abbey = Person(name: "Abbey Road", age: 29) | |
| let home = Address(street: "Abbey Road", houseNumber: 29) | |
| if abbey == home { | |
| print("They are structurally equal!") // Works! | |
| } |
Author
dterekhov
commented
Oct 17, 2025

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment