Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
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