Skip to content

Instantly share code, notes, and snippets.

@benpackard
Created March 31, 2016 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benpackard/7de27eff770072ca154a2f36283275ac to your computer and use it in GitHub Desktop.
Save benpackard/7de27eff770072ca154a2f36283275ac to your computer and use it in GitHub Desktop.
Feedable protocol for Array of Photos
import Foundation
class Photo {
let title: String
init(title: String) {
self.title = title
}
}
protocol Feedable {
var feedDescription: String { get }
}
extension Photo: Feedable {
var feedDescription: String {
return "A photo was added."
}
}
extension _ArrayType where Generator.Element == Photo {
var feedDescription: String {
return "\(count) photos were added."
}
}
let photo = Photo(title: "Photo 1")
let photos = [Photo(title: "Photo 2"), Photo(title: "Photo 3")]
let feedables: [Feedable] = [photo, photos]
for feedable in feedables {
print(feedable.feedDescription)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment