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:
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
Post a Comment