Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Ruby Flavor in Swift (3min)
1. Ruby Flavor in Swift
write your own
pseudo syntax sugar
2015/02/15
Swift Developers MeetUp in Tokyo
Hisakuni Fujimoto
2. Self-Introduction
• Hisakuni Fujimoto / 藤本尚邦
• @fhisa, https://github.com/hisa
• Freelance Programmer (野良プログラマ)
• RubyCocoa.framework creator
• It had been installed in Mac OS X from 10.5 to 10.9.
• iOS developer of half year experience
13. if let delegate = delegate {
if delegate.respondsToSelector("cameraPickerDidCancel:") {
NSOperationQueue.mainQueue().addOperationWithBlock {
delegate.cameraPickerDidCancel!(self)
}
}
}
Normally
delegate method invocation
• validate the delegate property
• test responsibility
• (wrap in main thread if need)
• invoke the method
15. func ifRespondTo(selector: Selector, handler:CameraPickerDelegate->Void) {
if let delegate = self.delegate {
if delegate.respondsToSelector(selector) {
NSOperationQueue.mainQueue().addOperationWithBlock {
handler(delegate)
}
}
}
}
Implementation of pseudo Syntax Sugar
delegate method invocation
• validate the delegate property
• test responsibility
• (wrap in main thread if need)
• invoke the method in handler
17. Summary
1. Swift has closure syntax sugar similar to the
block syntax of Ruby.
2. Make your pseudo syntax sugar using
closure argument if necessary. To keep
simple your source code!