How to change the element of array in swift -


i'm having difficulty function:

func sort(source: array<int>!) -> array<int>! {    source[0] = 1     ......     return source } 

an error happens:

enter image description here

why can't directly assign value specific element in array?

the variable sort immutable because it's parameter. need create mutable instance. also, there's no reason have parameter , return value implicitly unwrapped optionals ! operator.

func sort(source: array<int>) -> array<int> {    var anothersource = source // mutable version    anothersource[0] = 1    ......    return anothersource } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -