Created
May 11, 2016 15:55
-
-
Save curtisforrester/6e75bbb5fea6c1e9f89b461d2390cccb to your computer and use it in GitHub Desktop.
With closure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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