Swift - fatal error: Array index out of range

后端 未结 1 341
离开以前
离开以前 2020-12-04 03:29

I\'m trying to populate an array with numbers with an increase of 0.1 each like: [0.1,0.2,0.3...]

This code is giving me the error: fatal error: Array index ou

相关标签:
1条回答
  • 2020-12-04 03:41

    You can not add items to a Swift array with the subscript operator, you need to use append.

    NOTE You can’t use subscript syntax to append a new item to the end of an array.”

    Excerpt From: Apple Inc. “The Swift Programming Language (Swift 2 Prerelease).” iBooks. https://itun.es/us/k5SW7.l

    Use append(), examples:

    shoppingList.append("Flour")
    pickerData.append(0.1)
    
    0 讨论(0)
提交回复
热议问题