Skip to content

Instantly share code, notes, and snippets.

@kazmasaurus
Last active August 29, 2015 14:25
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 kazmasaurus/aab5362f3aece0e4d6a8 to your computer and use it in GitHub Desktop.
Save kazmasaurus/aab5362f3aece0e4d6a8 to your computer and use it in GitHub Desktop.
Potential solution to Brent's problem
//: Playground - noun: a place where people can play
import Cocoa
protocol Feed {
var url: String {get}
}
protocol Folder {
typealias FeedType
var feeds: [FeedType] {get}
func addFeeds(feedsToAdd: [FeedType])
}
class LocalFeed: Feed {
var url: String
init(url: String) {
self.url = url
}
}
extension LocalFeed: Equatable { }
func ==(lhs: LocalFeed, rhs: LocalFeed) -> Bool {
return lhs.url == rhs.url
}
class LocalFolder<F: Feed where F: Equatable>: Folder {
typealias FeedType = F
var feeds = [FeedType]()
func addFeeds(feedsToAdd: [FeedType]) {
for oneFeed in feedsToAdd {
if !feeds.contains(oneFeed) {
feeds += [oneFeed]
}
}
}
}
let folder = LocalFolder<LocalFeed>()
@kazmasaurus
Copy link
Author

Not sure if this satisfies all your requirements, but it seems like making Folder generic through an associated type might get you to where you want to be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment