Created
January 30, 2017 14:20
-
-
Save exce11ent/161aabc1892c715a47dba2532e0902aa 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
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