Reader small image

You're reading from  iOS 17 Programming for Beginners - Eighth Edition

Product typeBook
Published inOct 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781837630561
Edition8th Edition
Languages
Tools
Right arrow
Author (1)
Ahmad Sahar
Ahmad Sahar
author image
Ahmad Sahar

Ahmad Sahar is a trainer, presenter, and consultant at Tomafuwi Productions, specializing in conducting training courses for macOS and iOS, macOS Support Essentials certification courses, and iOS Development courses. He is a member of the DevCon iOS and MyCocoaHeads online communities in Malaysia and has conducted presentations and talks for both groups. In his spare time, he likes building and programming LEGO Mindstorms robots.
Read more about Ahmad Sahar

Right arrow

Exploring arrays

Let’s say you want to store the following:

  • List of items to buy at a convenience store.
  • Chores that you must do every month.

Arrays would be suitable for this. An array stores values in an ordered list. Here’s what it looks like:

Figure 5.1: Array

Values must be of the same type. You can access any value in an array by using the array index, which starts with 0.

If you create an array using the let keyword, its contents can’t be changed after it has been created. If you want to change an array’s contents after creation, use the var keyword.

Let’s see how to work with arrays. You’ll create an array by assigning a value to it in the next section.

Creating an array

In previous chapters, you created a constant or variable by declaring it and assigning an initial value to it. You can create an array the same way.

Imagine that your spouse has asked you to get some items...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
iOS 17 Programming for Beginners - Eighth Edition
Published in: Oct 2023Publisher: PacktISBN-13: 9781837630561

Author (1)

author image
Ahmad Sahar

Ahmad Sahar is a trainer, presenter, and consultant at Tomafuwi Productions, specializing in conducting training courses for macOS and iOS, macOS Support Essentials certification courses, and iOS Development courses. He is a member of the DevCon iOS and MyCocoaHeads online communities in Malaysia and has conducted presentations and talks for both groups. In his spare time, he likes building and programming LEGO Mindstorms robots.
Read more about Ahmad Sahar