Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift XctestExpection应该如何初始化?_Swift_Xctest - Fatal编程技术网

Swift XctestExpection应该如何初始化?

Swift XctestExpection应该如何初始化?,swift,xctest,Swift,Xctest,有两个选项可以用来初始化xtestexpection。首先,使用直接初始值设定项 import XCTest class MyTests: XCTestCase { let expectation = XCTestExpectation(description: "foo")` } 然后使用XCTest实例方法 import XCTest class MyTests: XCTestCase { let expectation = self.expectation(descr

有两个选项可以用来初始化
xtestexpection
。首先,使用直接初始值设定项

import XCTest

class MyTests: XCTestCase {
    let expectation = XCTestExpectation(description: "foo")`
}
然后使用
XCTest
实例方法

import XCTest

class MyTests: XCTestCase {
    let expectation = self.expectation(description: "foo")
}

两种方法产生相同的结果,所以我想知道哪种方法更好?直接
xTestExpection
初始值设定项快一点吗?

最大的区别在于是否要使用
WaitForExpections(超时:时间间隔,处理程序:xWaitCompletionHandler)

WaitForExpections(超时:时间间隔,处理程序:XCWaitCompletionHandler)
只能在使用
self.expectation(description:“foo”)
创建期望时使用


否则,您需要调用
wait(期望值:[xTestExpection],超时秒数:TimeInterval)

最大的区别在于您是否要使用
WaitForExpections(超时:TimeInterval,处理程序:xWaitCompletionHandler)

WaitForExpections(超时:时间间隔,处理程序:XCWaitCompletionHandler)
只能在使用
self.expectation(description:“foo”)
创建期望时使用

否则,您需要调用
wait(期望值:[xctestexpection],超时秒数:TimeInterval)