Skip to content

Instantly share code, notes, and snippets.

@derrickshowers
Created April 18, 2015 23:54
Show Gist options
  • Save derrickshowers/80fb450490ff03e6e274 to your computer and use it in GitHub Desktop.
Save derrickshowers/80fb450490ff03e6e274 to your computer and use it in GitHub Desktop.
Delegation Design Pattern Using Swift
import UIKit
protocol YelpRequestDelegate {
func getYelpData() -> AnyObject
func processYelpData(data: NSData) -> NSData
}
class YelpAPI {
var delegate: YelpRequestDelegate?
func getData() {
println("data being retrieved...")
let data: AnyObject? = delegate?.getYelpData()
}
func processYelpData(data: NSData) {
println("data being processed...")
let data = delegate?.processYelpData(data)
}
}
class Controller: YelpRequestDelegate {
init() {
var yelpAPI = YelpAPI()
yelpAPI.delegate = self
yelpAPI.getData()
}
func getYelpData() -> AnyObject {
println("getYelpData called")
return NSData()
}
func processYelpData(data: NSData) -> NSData {
println("processYelpData called")
return NSData()
}
}
var controller = Controller()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment