Is it "one of those days", or is it just me? I must be missing something obvious. Please tell me the bug is in my mind and not in Swift 1.2 or Xcode 6.3.

I've defined the following class, and trying to test it. But when I invoke a function with seemingly correct formal and actual parameters, Swift 1.2 reports Expected Declaration.

I have no idea what's wrong with it.

*Note: I made the class because I was having trouble getting an array passed by reference (inout / &) to propagate the changes made in the called function. That was weird too.

    class TableData {

        var dataArrays = [UITableView : [String]]()

        func addArray(obj : UITableView, _ initialValues : [String] ) {
            dataArrays[obj] = [String]()
            dataArrays[obj]?.extend(initialValues)
        }
        func swapItems(tv : UITableView, _ rowa: Int, _ rowb : Int) {
            var item1 = dataArrays[tv]![rowa - 1] as String
            var item2 = dataArrays[tv]![rowb - 1] as String
            dataArrays[tv]![rowa - 1] = item2
            dataArrays[tv]![rowb - 1] = item1
        }

        func moveItem(srcTbl: UITableView, _ srcRow : Int, _ dstTbl: UITableView, _ dstRow: Int) {
            var item = getItem(srcTbl, srcRow - 1)
            insertItem(dstTbl, dstRow - 1, item)
            deleteItem(srcTbl, srcRow - 1)
        }

        func insertItem(tv : UITableView, _ row: Int, _ value: String) {
            dataArrays[tv]![row - 1] = value
        }

        func getItem(tv: UITableView, _ row: Int) -> String {
           return dataArrays[tv]![row - 1]
        }

        func deleteItem(tv: UITableView, _ row: Int) {
            dataArrays[tv]!.removeAtIndex(row - 1)
        }

        func count(tv: UITableView) -> Int {
            return dataArrays[tv]!.count
        }

        func printItems(tv: UITableView, title: String? = nil) {
            if title != nil {
                println("\(title):")
            }
            for i in 0..<dataArrays[tv]!.count {
                var item = dataArrays[tv]![i]
                println("\(i) \"\(item)\"")
            }
        }
    }

enter image description here

Related posts

Recent Viewed