Search code examples
arraysswiftxcodeparentheses

Array in Swift Xcode


I have an algorithm that intersects some array with Bool and give me back some other array. Now the problem is that the arrays I get has this form: [[[[123.0,334.45]]],[[[342.35,2434.34]]],[[[...,...]]],....]

Now how you can see there are too Square brackets, is there any way to remove the parentheses too ? thanking you.


Solution

  • Whew, now that's nesting!

    I counted the brackets, and used the appropriate number of joined() methods to flatten the array:

    let array = [[[[123.0,334.45]]],[[[342.35,2434.34]]]]
    let flatArray = Array(array.joined().joined().joined())
    

    ...gives:

    [123, 334.45, 342.35, 2434.34]