 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Swift Program to Convert Set into Array
In Swift, a set is used to define an unordered collection of unique elements whereas an array is used to define an ordered collection with may or may not be unique elements. To convert a set into an array Swift provides an inbuilt initializer named as Array().
Syntax
Array(MySet)
Where Array() initializer takes only one parameter that is the name of the set and, returns an array of the same type.
Example
In the following example, we will create and initialize a set of strings. Then convert the set into the array using Array() initializer and then display the output.
import Foundation
import Glibc
// Creating a set of string
var myFavfruit : Set = ["Orange", "Sweet apple", "Apple", "Kiwi", "Mango", "Jackfruit"] 
// Converting a set into array
var resArray = Array(myFavfruit)
print("Array: ", resArray)
Output
Array: ["Mango", "Orange", "Kiwi", "Jackfruit", "Sweet apple", "Apple"]
Conclusion
Therefore, this is how we can convert a set into an array. However, it is not necessary that the order of the elements in the resultant array is the same as the original set because sets are the unordered collection.
