Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum MyEnum {
- case one
- case two
- case three(user: String)
- func isOfSameType(_ other: MyEnum) -> Bool {
- switch (self, other) {
- case (.one, .one):
- return true
- case (.two, .two):
- return true
- case (.three, .three):
- return true
- default:
- return false
- }
- }
- }
- var array: [MyEnum] = []
- func add(_ value: MyEnum) {
- if array.contains(where: { value.isOfSameType($0) }) { return }
- array.append(value)
- }
- add(.one)
- print(array)
- add(.two)
- print(array)
- add(.three(user: "Carl"))
- print(array)
- add(.three(user: "Junior"))
- print(array)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement