Created
September 23, 2014 18:57
-
-
Save zhangxigithub/a73f4fa5c52c4de66562 to your computer and use it in GitHub Desktop.
Swift_Chain
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 UIKit | |
class Person:NSObject | |
{ | |
var name:String! | |
init(name:String){ | |
self.name = name | |
println("init \(name)") | |
} | |
func shopping(shop:String)->Action | |
{ | |
println("\(name) go \(shop)") | |
let action = Action(master:self) | |
action.master = self | |
return action | |
} | |
} | |
class Action:NSObject | |
{ | |
var master:Person! | |
init(master:Person) { | |
self.master = master | |
} | |
func action(action:String) | |
{ | |
println(master.name + " " + action) | |
} | |
} | |
println("1. -----") | |
Person(name:"zhangxi") | |
println("2. -----") | |
Person(name:"zhangxi").shopping("market") | |
println("3. -----") | |
Person(name:"zhangxi").shopping("market").action("buy something") | |
/* | |
1. ----- | |
init zhangxi | |
2. ----- | |
init zhangxi | |
zhangxi go market | |
3. ----- | |
init zhangxi | |
zhangxi go market | |
zhangxi buy something | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment