Skip to content

Instantly share code, notes, and snippets.

@exce11ent
Created January 30, 2017 14:20
Show Gist options
  • Save exce11ent/161aabc1892c715a47dba2532e0902aa to your computer and use it in GitHub Desktop.
Save exce11ent/161aabc1892c715a47dba2532e0902aa to your computer and use it in GitHub Desktop.
class PostImagesModel {
enum CellImage {
case Required, Add, Actual(image: UIImage), Remote(url: NSURL)
}
private let maxLimit = 6
private var items: [CellImage] = []
func add(image: UIImage) {
items.append(.Actual(image: image))
}
func add(url: NSURL) {
items.append(.Remote(url: url))
}
func remove(index: Int) {
guard index < items.count else { return }
items.removeAtIndex(index)
}
var toDisplay: [CellImage] {
get {
guard !items.isEmpty else {
return [.Required]
}
var toReturn = items
if items.count < maxLimit {
toReturn.append(.Add)
}
return toReturn
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment