Avatar ·

How to remove duplicates from an array in Swift? (Preserving order)

Hello! I'm new to Swift and encountered a problem. I have an array of strings that may contain duplicate values. For example: ```swift let names = ["Anna", "Boris", "Anna", "Victor", "Boris", "Dmitry"] ``` I need to get a new array where each element appears only once, but the order of elements must be preserved (first occurrence). That is, the result should be: `["Anna", "Boris", "Victor", "Dmitry"]`. I know that you can use `Set`, but it does not guarantee the order of elements. I also tried `NSOrderedSet`, but it's from Objective-C, and I think there should be a more elegant solution in Swift. Tell me how to properly remove duplicates from an array in Swift, preferably using the standard library, without importing Foundation.