Tim Dietrich

Custom Software Developer

Home Services Portfolio Blog About Contact Newsletter

Swift: Easily Remove All Rows From A WatchKit Table

I'm making improvements to an Apple Watch app today. One of the features that I'm working on requires that the rows of a table (a WKInterfaceTable object) be completely cleared prior to being reloaded.

This is insanely easy to do. You can use the removeRowsAtIndexes method of the WKInterfaceTable class, and pass the full range of row indexes.

Here's a Swift code snippet that shows how the technique works.

// Clear all rows from the table.
codeTable.removeRowsAtIndexes(NSIndexSet(indexesInRange: NSRange(location: 0, length: codeTable.numberOfRows)))