1

I'm incredibly new to swift and I'm sure this question has been asked before, but I have no idea of the terminology of what to search.

I've seen how to do this before, but not sure where. I want to be able to loop though my arrays using a count, like the below (but that is not working). So the last number of the array name changes depending on the count. So if myCount = 0 then myArray will equal array_0001_00 and if my count = 6 then myArray will equal array_0001_06, and so on.

I'm not sure if I'm missing something small or if I'm completely on the wrong track.

let array_0001_00 = [102,102,102,102,102,102,102,102]
let array_0001_01 = [112,112,112,112,112,112,112,112]
myArray = array_0001_0\(myCount)

Any help would be much appreciated. Thanks.

I'm currently using the below, which works, but is creating a mountain of code:

if myCount == 0 {
    myArray = array_0001_00
} else if myBuilderCountY == 1 {
    myArray = array_0001_01
} 
2
  • To me its really not clear what you want. Could you explain this better? Commented May 16, 2015 at 7:33
  • I've edited my question a little to try and explain better, let me know if this is any more clearer, if not, I'll try explain a little more. I'm sorry, I alway find it hard explain myself on here. Commented May 16, 2015 at 7:40

1 Answer 1

1

I hope I haven't misunderstood - you have a number of arrays, and you want to select one of them using an index. That looks like selecting an element from an array:

let array_0001_00 = [102,102,102,102,102,102,102,102]
let array_0001_01 = [112,112,112,112,112,112,112,112]
let array_0001_02 = [122,122,122,122,122,122,122,122]

let array_of_arrays = [
    array_0001_00,
    array_0001_01,
    array_0001_02
]

let index = 1
let myArray = array_of_arrays[index] // This assigns (a copy of) array_0001_01
Sign up to request clarification or add additional context in comments.

1 Comment

Different approach then what I was thinking, but this does exactly what I trying to achieve. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.