Swift: Convert to Base -2
swift\nimport Foundation\n\nclass Solution {\n    func baseNeg2(_ n: Int) -> String {\n        if n == 0 { return n.description }\n        var chs = [Character]
```swift\nimport Foundation\n\nclass Solution {\n    func baseNeg2(_ n: Int) -> String {\n        if n == 0 { return n.description }\n        var chs = [Character]()\n        var n = n\n        while n != 0 {\n            chs.append(contentsOf: String(n & 1))\n            n = -(n >> 1)\n        }\n        return String(chs.reversed())\n    }\n}\n```\n\n```swift\nimport XCTest\n\n//      Executed 3 tests, with 0 failures (0 unexpected) in 0.006 (0.007) seconds\n\nclass Tests: XCTestCase {\n    private let s = Solution()\n    func test1() {\n        XCTAssertEqual(s.baseNeg2(2), "110")\n    }\n    func test2() {\n        XCTAssertEqual(s.baseNeg2(3), "111")\n    }\n    func test3() {\n        XCTAssertEqual(s.baseNeg2(4), "100")\n    }\n}\n\nTests.defaultTestSuite.run()\n```
['Swift']