I can currently get rid of repeating objects in an array, but I want to call that array in the indexPath.row method, but I get the error that the variable is not defined since it is declared in a function. I tried instantiating as a nil globally, but that does not get rid of the repeating objects.
Var myVar = [<the T type>]() uniq(<some source>, uniqueTitle: &myVar) func uniq<S : SequenceType, T : Hashable where S.Generator.Element == T>(source: S) -> [T] { var buffer = [T]() var added = Set<T>() for elem in source { if !added.contains(elem) { buffer.append(elem) added.insert(elem) } } return buffer } //titleatcell is an array with repeating objects. titleatcell.append(title!) var uniqueTitle = uniq(titleatcell) uniqueTitle.append(title!) print(uniqueTitle) //return count of objects in array } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = table.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) //Error: uniqueTitle is not declared. cell.textLabel?.text = uniqueTitle[indexPath.row] return cell }
cell.textLabel?.text = uniq(titleatcell)[indexPath.row]uniqas a nested function. Is that really what you wanted to do? If not, bring the declaration ofuniqto your class scope, like right beforetableView(t:cellForRowAtIndexPath:).