Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Append variables to an array using swift I have 100 variables of type UITextFiel

ID: 3718575 • Letter: A

Question

Append variables to an array using swift

I have 100 variables of type UITextField that are named as such

box00, box01, box02 ........ box99

I would like to assign to each of these boxes something, however I am stuck. I tried to programmatically stuff them all in an array but I am stuck with that as well.

When using a counter in the variable name my compiler doesn't recognize the variable. I tried making a nested for loop.

        for i in 0...9{
            for j in 0...9{
                boxArray.append(box(i)(j))
            }
        }

Any ideas what I do now that I'm in this situation? I want all of my 100 UITextField variables appended in an array without explicitly naming each one by one.

Explanation / Answer

Source Code:-
----------------------
package com.samples;
public class Append_Variable
{
public static void main(String[] args)
{
String[] boxArray=new String[101];
String Box = " ";
for(int k=0,i=0,j=0;k<=99;k++)
{
Box=Box.concat("Box"+i+j);
if(j==9)
{
i++;
j=-1;
}
j++;
boxArray[k]=Box;
Box="";
}
System.out.println("The Box Variable Names Are: ");
System.out.println(" ------------------------------");
for(int j=0;j<=99;j++)
{
System.out.println(boxArray[j]);
}
}
}

Sample Output:-
-----------------------
The Box Variable Names Are:

------------------------------
Box00
Box01
Box02
Box03
Box04
Box05
Box06
Box07
Box08
Box09
Box10
Box11
Box12
Box13
Box14
Box15
Box16
Box17
Box18
Box19
Box20
Box21
Box22
Box23
Box24
Box25
Box26
Box27
Box28
Box29
Box30
Box31
Box32
Box33
Box34
Box35
Box36
Box37
Box38
Box39
Box40
Box41
Box42
Box43
Box44
Box45
Box46
Box47
Box48
Box49
Box50
Box51
Box52
Box53
Box54
Box55
Box56
Box57
Box58
Box59
Box60
Box61
Box62
Box63
Box64
Box65
Box66
Box67
Box68
Box69
Box70
Box71
Box72
Box73
Box74
Box75
Box76
Box77
Box78
Box79
Box80
Box81
Box82
Box83
Box84
Box85
Box86
Box87
Box88
Box89
Box90
Box91
Box92
Box93
Box94
Box95
Box96
Box97
Box98
Box99

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote