Skip to content

Instantly share code, notes, and snippets.

cellAtIndexPath [0, 0]
will display cell [0, 0]
cellAtIndexPath [0, 1]
will display cell [0, 1]
cellAtIndexPath [0, 2]
will display cell [0, 2]
cellAtIndexPath [0, 3]
will display cell [0, 3]
cellAtIndexPath [0, 4]
will display cell [0, 4]
cellAtIndexPath [0, 0]
will display cell [0, 0]
cellAtIndexPath [0, 1]
will display cell [0, 1]
cellAtIndexPath [0, 2]
will display cell [0, 2]
cellAtIndexPath [0, 3]
will display cell [0, 3]
cellAtIndexPath [0, 4]
will display cell [0, 4]
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if let visibleIndexPaths = tableView.indexPathsForVisibleRows, visibleIndexPaths.contains(indexPath) {
print("will display cell \(indexPath)")
}
}
cellAtIndexPath [0, 0]
will display cell [0, 0]
cellAtIndexPath [0, 1]
will display cell [0, 1]
cellAtIndexPath [0, 2]
will display cell [0, 2]
cellAtIndexPath [0, 3]
will display cell [0, 3]
cellAtIndexPath [0, 4]
will display cell [0, 4]
class TableViewPaginationTest: XCTestCase {
func testExample() {
XCUIApplication().launch()
print(XCUIApplication().tables.cells.count)
}
}
class ViewController: UITableViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
print("will display cell \(indexPath)")
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.count + moreItemsToLoad ? 1 : 0
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if cell is TableViewCellLoadingCell {
fetchNewItems()
}
}
func testCustomBlock() {
let someObjectToInject: AnyObject = ...
// this will invoke the code of block in ViewController.swift
app.performCustomCommandNamed("myCustomCommandKey", object: someObjectToInject)
}
func testRequestMonitor() {
// listen to all calls made to `(.*)apple(.*)`
app.monitorRequestsWithRegex("(.*)myserver(.*)")
// interact with UI
// check that there's everything you're expecting
let requests: [SBTMonitoredNetworkRequest] = app.monitoredRequestsFlushAll()
for request in requests {
func testFilesystem() {
let pathToFile = "MyFakeDB.sqlite"
app.uploadItemAtPath(pathToFile, toPath: "/db/db.sqlite", relativeTo: .DocumentDirectory)
// interact with UI
let uploadData = app.downloadItemFromPath("/db/db.sqlite", relativeTo: .DocumentDirectory)
// check that file was modified as expected
}