Created
February 8, 2017 07:20
-
-
Save madhu314/0bf3609cffcd74ff44a220384fe8541c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func toggleCompleted(forItem listItem: ListItem, on collectionView: UICollectionView) { | |
let foundIndex = items.index { (given) -> Bool in | |
return given.id == listItem.id | |
} | |
if(listItem.isCompleted) { | |
if let index = foundIndex { | |
let item = items.remove(at: index) | |
items.insert(item, at: 0) | |
item.isCompleted = false | |
collectionView.moveItem(at: IndexPath(item: index, section: 0), to: IndexPath(item: 0, section: 0)) | |
} | |
} else { | |
if let index = foundIndex { | |
let item = items.remove(at: index) | |
items.append(item) | |
item.isCompleted = true | |
collectionView.moveItem(at: IndexPath(item: index, section: 0), to: IndexPath(item: items.count - 1, section: 0)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment