Chapter 3. Using Swift Collections and the Tuple Type
Once I got past the basic Hello World beginner applications, I quickly began to realize the shortcomings of variables, especially with the Mad Libs-style applications that I was starting to write. These applications requested that the user enter numerous strings, and I was creating a separate variable for each input field that the user entered. Having all of these separate variables quickly became very cumbersome. I remember talking to a friend about this and he asked me why I was not using arrays. At that time, I was not familiar with arrays, so I asked him to show me what they were. Even though he had a TI-99/4A and I had a Commodore Vic-20, the concept of arrays was the same. Even today, the arrays found in modern development languages have the same basic concepts as the arrays I used on my Commodore Vic-20. While it is definitely possible to create a useful application without using collections, when used properly, collections do make application development significantly easier.
In this chapter, we will cover the following topics:
- What an array is in Swift and how to use it?
- What a dictionary is in Swift and how we can use it?
- What a set is in Swift and how we can use it?
- What a tuple is in Swift and how we can use it?