✅ [Solution] Swift: Insert Interval (+ test cases)
swift\nclass Solution {\n    func insert(_ intervals: [[Int]], _ newInterval: [Int]) -> [[Int]] {\n        guard !intervals.isEmpty else { return [newInterval] 
```swift\nclass Solution {\n    func insert(_ intervals: [[Int]], _ newInterval: [Int]) -> [[Int]] {\n        guard !intervals.isEmpty else { return [newInterval] }\n        guard !newInterval.isEmpty else { return intervals }\n        \n        var idx = 0, new = newInterval, result: [[Int]] = []\n        let len = intervals.count\n        \n        while idx < len, intervals[idx][1] < new[0] {\n            result.append(intervals[idx])\n            idx += 1\n        }\n        \n        while idx < len, intervals[idx][0] <= new[1] {\n            new[0] = min(intervals[idx][0], new[0])\n            new[1] = max(intervals[idx][1], new[1])\n            idx += 1\n        }\n        \n        result.append(new)\n        \n        for i in idx..<len { result.append(intervals[i]) }\n        \n        return result\n    }\n}\n```\n\n---\n\n<p>\n<details>\n<summary>\n<img src="https://git.io/JDblm" height="24">\n<b>TEST CASES</b>\n</summary>\n\n<p><pre>\n<b>Result:</b> Executed 2 tests, with 0 failures (0 unexpected) in 0.010 (0.012) seconds\n</pre></p>\n\n```swift\nimport XCTest\n\nclass Tests: XCTestCase {\n    \n    private let solution = Solution()\n    \n    func test0() {\n        let value = solution.insert([[1,3],[6,9]], [2,5])\n        XCTAssertEqual(value, [[1,5],[6,9]])\n    }\n    \n    // Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].\n    func test1() {\n        let value = solution.insert([[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8])\n        XCTAssertEqual(value, [[1,2],[3,10],[12,16]])\n    }\n}\n\nTests.defaultTestSuite.run()\n```\n\n</details>\n</p>
['Swift']