Swift:不能覆盖本地范围内的类函数

时间:2014-09-28 05:55:34

标签: ios swift

当我写这篇文章时:

func testMock() {
    class MockAPI: API {
        var expectation: XCTestExpectation?

        init(expectation: XCTestExpectation) {
            self.expectation = expectation
        }

        override func method() {
            expectation!.fulfill()
        }
    }

    let mockAPI = MockAPI(expectation: self.expectationWithDescription("API: method should be called"))

    ...

    self.waitForExpectationsWithTimeout(1, handler: nil)
}

我收到错误:Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

有什么想法吗?

为了澄清一点,因为OCMock不能使用swift,我试图复制这里描述的模拟行为NSHipster / Test(它在博客文章的末尾)。

值得一提的是,最初我想要的是:

func testMock() {
    let expectation = self.expectationWithDescription("API: method should be called")

    class MockAPI: API {
        override func method() {
            expectation.fulfill()
        }
    }

    let mockAPI = MockAPI()

    ...

    self.waitForExpectationsWithTimeout(1, handler: nil)
}

但是我得到了“SourceKitService Crashed”,类似于我认为的这个问题SourceKitService Terminated

0 个答案:

没有答案