Swift🫧clean
Simulation (accepted answer)\n\nclass Solution {\n    func spiralMatrixIII(_ rows: Int, _ cols: Int, _ rStart: Int, _ cStart: Int) -> [[Int]] {\n        var res
**Simulation (accepted answer)**\n```\nclass Solution {\n    func spiralMatrixIII(_ rows: Int, _ cols: Int, _ rStart: Int, _ cStart: Int) -> [[Int]] {\n        var result = [[Int]]()\n        let deltas = [0,1,0,-1,0]\n        var pos = [rStart, cStart] // [yPos, xPos]\n        var direction = 0  // 0=east 1=south 2=west 3=north\n        var bounds = [cStart+1, rStart+1, cStart-1, rStart-1]\n        \n        while result.count < rows*cols {\n            // if within matrix, output position\n            if 0..<rows ~= pos[0], 0..<cols ~= pos[1] {\n                result.append(pos)\n            }\n            \n            // update position\n            pos = zip(pos, deltas[direction...]).map(+)\n            \n            // if hit bounds, update edge and direction \n            if pos[1-direction&1] == bounds[direction] {\n                bounds[direction] += 1-(direction&2) // looks fancy, but just +/- 1\n                direction = (direction+1) % 4\n            }\n        }\n        return result\n    }\n}\n```
['Swift']