Created
March 31, 2016 03:53
-
-
Save benpackard/7de27eff770072ca154a2f36283275ac to your computer and use it in GitHub Desktop.
Feedable protocol for Array of Photos
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
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