-11

If I have an array with elements linked to xassets with names like "card1", "card2", etc up to "card100" is there a quicker way to write these elements in the array format without having to write out all 100?

Also if this has been answered already please let me know or link to it. About 2 days into trying to teach myself to program.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 3
    What does "linked to xassets" mean? What are "xassets"? Please show actual code; also show an example of your desired input and output. – matt Jul 19 '16 at 04:53
  • 2
    Update your question with relevant code. – rmaddy Jul 19 '16 at 04:55
  • 1
    If you're just starting out, asking questions on Stack Overflow is not the place you need to be. You should find a good book or a series of online tutorials. Look at [the \[swift\] tag wiki for some resources](http://stackoverflow.com/tags/swift/info). If you're working on an Apple system, you could also take a look at [Good resources for learning ObjC](http://stackoverflow.com/q/1374660), which is really about Cocoa programming, and many of the items are updated to use Swift. Good luck! – jscs Jul 19 '16 at 05:10

2 Answers2

-1

Not exactly sure what you're asking but you may want to look at loops - Swift Loops. You can add items to an array in a for loop from 1 to 100.

Albert Ghar
  • 428
  • 1
  • 6
  • 14
-1

Is this what you are looking for ?

let cards = Array(1...100).map({"card\($0)"})
Alain T.
  • 40,517
  • 4
  • 31
  • 51