Skip to content

Instantly share code, notes, and snippets.

@curtisforrester
Created May 11, 2016 15:55
Show Gist options
  • Save curtisforrester/6e75bbb5fea6c1e9f89b461d2390cccb to your computer and use it in GitHub Desktop.
Save curtisforrester/6e75bbb5fea6c1e9f89b461d2390cccb to your computer and use it in GitHub Desktop.
With closure
struct SelectedTagDetail {
var id: Int = 0
var name: String = ""
}
typealias SelectedTagsClosure = (tags: [SelectedTagDetail]) -> Void
class BudgetTagsTableViewController: UITableViewController, BNDTableViewProxyDataSource {
// ...
var selectedTagIDs = Set<Int>()
var onCloseSelectedTags: SelectedTagsClosure?
// ...
override func viewWillDisappear(animated: Bool) {
if self.isMovingFromParentViewController() && self.onCloseSelectedTags != nil {
let selected = self.dataArray.filter({self.selectedTagIDs.contains($0.id)})
let detailList = selected.map{ (tag) -> SelectedTagDetail in
return SelectedTagDetail(id: tag.id, name: tag.tag)
}
self.onCloseSelectedTags?(tags: detailList)
}
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment