Welcome to the Treehouse Community
Looking to learn something new?
Why we need to write "atIndex" instead of todo.insert("element", 3) for example ?
I already used other programming language and the function "knows" that the second argument would be the index so why we need to write "atIndex:", whereas we dont write "newElement:" before the first argument. Thanks !
atIndex is the required parameter name for apple's provided function "insert". If you were to attempt to insert a String into an array of Strings at the second position, or 3rd index, using
Then the Int 3 is unresolved and doesn't signify anything. It needs to signify the placement in the array that "element" should be inserted- "3" by itself doesn't do that. Only by using the atIndex keyword does the number 3 represent a 3rd index or second placement in an array.
Yes I got that I need to write it, I was just suggesting that the function could know that the second argument is the index, without writing "atIndex" !
Thanks for the answer btw !