SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
Ruby Flavor in Swift
write your own
pseudo syntax sugar
2015/02/15
Swift Developers MeetUp in Tokyo
Hisakuni Fujimoto
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
Syntax sugar
of
closure argument
queue.addOperationWithBlock({
...
})
Inside of □ is a closure argument.
Base Syntax of Swift
Passing closure argument in parentheses
like Objective-C, JavaScript and etc.
queue.addOperationWithBlock() {
...
}
Syntax Sugar of Swift
Closure argument go out parentheses
of argument list.
Syntax Sugar of Swift
When other argument is nothing,
omission of parentheses is possible.
queue.addOperationWithBlock {
...
}
The person who proposed
this syntax surely likes Ruby.
Because..
block syntax of Ruby
queue.addOperationWithBlock do
...
end
queue.addOperationWithBlock {
...
}
or
block syntax of Ruby
queue.addOperationWithBlock {
...
}
完全に一致
Completely Match
Write your own
pseudo syntax sugar
In Ruby on Rails app,
Podfile of CocoaPods
and etc,block syntax of
Ruby is used very well.
We can do same
thing using Swift.
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
Pseudo Syntax Sugar
delegate method invocation
ifRespondTo("cameraPickerDidCancel:") {
$0.cameraPickerDidCancel!(self)
}
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
Pseudo Syntax Sugar (again)
delegate method invocation
ifRespondTo("cameraPickerDidCancel:") {
$0.cameraPickerDidCancel!(self)
}
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!
2015/02/15
Swift Developers MeetUp in Tokyo
Hisakuni Fujimoto
Thank You!

Mais conteúdo relacionado

Mais procurados

It's a Jungle Out There – IoT and MRuby
It's a Jungle Out There – IoT and MRubyIt's a Jungle Out There – IoT and MRuby
It's a Jungle Out There – IoT and MRubymatustomlein
 
Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28Mark Stoodley
 
mRuby - Powerful Software for Embedded System Development
mRuby - Powerful Software for Embedded System DevelopmentmRuby - Powerful Software for Embedded System Development
mRuby - Powerful Software for Embedded System DevelopmentKazuhiro Koga 古賀一博
 
freeCodeCamp Tokyo meetup 19
freeCodeCamp Tokyo meetup 19freeCodeCamp Tokyo meetup 19
freeCodeCamp Tokyo meetup 19健太 田上
 
Onivim: Modal Editing from the Future
Onivim: Modal Editing from the FutureOnivim: Modal Editing from the Future
Onivim: Modal Editing from the FutureBryan Phelps
 
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...Mickael Istria
 
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020Andrew Yatsenko
 
IronRuby: Ruby on the .NET Platform
IronRuby: Ruby on the .NET PlatformIronRuby: Ruby on the .NET Platform
IronRuby: Ruby on the .NET PlatformAndre John Cruz
 
PyPy
PyPyPyPy
PyPyESUG
 
a quick Introduction to PyPy
a quick Introduction to PyPya quick Introduction to PyPy
a quick Introduction to PyPyKai Aras
 
Swift for back end: A new generation of full stack languages?
Swift for back end: A new generation of full stack languages?Swift for back end: A new generation of full stack languages?
Swift for back end: A new generation of full stack languages?Koombea
 

Mais procurados (17)

It's a Jungle Out There – IoT and MRuby
It's a Jungle Out There – IoT and MRubyIt's a Jungle Out There – IoT and MRuby
It's a Jungle Out There – IoT and MRuby
 
Crystal
CrystalCrystal
Crystal
 
Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28
 
mRuby - Powerful Software for Embedded System Development
mRuby - Powerful Software for Embedded System DevelopmentmRuby - Powerful Software for Embedded System Development
mRuby - Powerful Software for Embedded System Development
 
Coding in kotlin
Coding in kotlinCoding in kotlin
Coding in kotlin
 
freeCodeCamp Tokyo meetup 19
freeCodeCamp Tokyo meetup 19freeCodeCamp Tokyo meetup 19
freeCodeCamp Tokyo meetup 19
 
hexMachina WWX 2016
hexMachina WWX 2016hexMachina WWX 2016
hexMachina WWX 2016
 
Onivim: Modal Editing from the Future
Onivim: Modal Editing from the FutureOnivim: Modal Editing from the Future
Onivim: Modal Editing from the Future
 
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
 
IronRuby: Ruby on the .NET Platform
IronRuby: Ruby on the .NET PlatformIronRuby: Ruby on the .NET Platform
IronRuby: Ruby on the .NET Platform
 
An Introduction to PyPy
An Introduction to PyPyAn Introduction to PyPy
An Introduction to PyPy
 
PyPy
PyPyPyPy
PyPy
 
a quick Introduction to PyPy
a quick Introduction to PyPya quick Introduction to PyPy
a quick Introduction to PyPy
 
Swift for back end: A new generation of full stack languages?
Swift for back end: A new generation of full stack languages?Swift for back end: A new generation of full stack languages?
Swift for back end: A new generation of full stack languages?
 
FunScript: Why bother?
FunScript: Why bother?FunScript: Why bother?
FunScript: Why bother?
 

Semelhante a Ruby Flavor in Swift (3min)

Dependent things dependency management for apple sw - slideshare
Dependent things   dependency management for apple sw - slideshareDependent things   dependency management for apple sw - slideshare
Dependent things dependency management for apple sw - slideshareCavelle Benjamin
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Asher Martin
 
CocoaConf DC - Automate with Swift - Tony Ingraldi
CocoaConf DC -  Automate with Swift - Tony IngraldiCocoaConf DC -  Automate with Swift - Tony Ingraldi
CocoaConf DC - Automate with Swift - Tony IngraldiTony Ingraldi
 
Geecon 2019 - Taming Code Quality in the Worst Language I Know: Bash
Geecon 2019 - Taming Code Quality  in the Worst Language I Know: BashGeecon 2019 - Taming Code Quality  in the Worst Language I Know: Bash
Geecon 2019 - Taming Code Quality in the Worst Language I Know: BashMichał Kordas
 
KWDC 2023-Swift 히스토리 탐방
KWDC 2023-Swift 히스토리 탐방KWDC 2023-Swift 히스토리 탐방
KWDC 2023-Swift 히스토리 탐방수환 조
 
Mobile Development integration tests
Mobile Development integration testsMobile Development integration tests
Mobile Development integration testsKenneth Poon
 
RESTful API Development using Go
RESTful API Development using GoRESTful API Development using Go
RESTful API Development using GoBaiju Muthukadan
 
Web application intro + a bit of ruby (revised)
Web application intro + a bit of ruby (revised)Web application intro + a bit of ruby (revised)
Web application intro + a bit of ruby (revised)Tobias Pfeiffer
 
Introduction to Ruby Native Extensions and Foreign Function Interface
Introduction to Ruby Native Extensions and Foreign Function InterfaceIntroduction to Ruby Native Extensions and Foreign Function Interface
Introduction to Ruby Native Extensions and Foreign Function InterfaceOleksii Sukhovii
 
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...Toshiaki Maki
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the RubyistWill Green
 
Try! Swift Tokyo2017
Try! Swift Tokyo2017Try! Swift Tokyo2017
Try! Swift Tokyo2017Amy Cheong
 
How to build SDKs in Go
How to build SDKs in GoHow to build SDKs in Go
How to build SDKs in GoDiwaker Gupta
 
RubyMotion Introduction
RubyMotion IntroductionRubyMotion Introduction
RubyMotion IntroductionLori Olson
 
Swimat - Swift formatter
Swimat - Swift formatterSwimat - Swift formatter
Swimat - Swift formatterJintin Lin
 
Swift 2.2 Design Patterns CocoaConf Austin 2016
Swift 2.2 Design Patterns CocoaConf Austin 2016Swift 2.2 Design Patterns CocoaConf Austin 2016
Swift 2.2 Design Patterns CocoaConf Austin 2016Carl Brown
 

Semelhante a Ruby Flavor in Swift (3min) (20)

ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
Dependent things dependency management for apple sw - slideshare
Dependent things   dependency management for apple sw - slideshareDependent things   dependency management for apple sw - slideshare
Dependent things dependency management for apple sw - slideshare
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3
 
CocoaConf DC - Automate with Swift - Tony Ingraldi
CocoaConf DC -  Automate with Swift - Tony IngraldiCocoaConf DC -  Automate with Swift - Tony Ingraldi
CocoaConf DC - Automate with Swift - Tony Ingraldi
 
Ruby
RubyRuby
Ruby
 
Geecon 2019 - Taming Code Quality in the Worst Language I Know: Bash
Geecon 2019 - Taming Code Quality  in the Worst Language I Know: BashGeecon 2019 - Taming Code Quality  in the Worst Language I Know: Bash
Geecon 2019 - Taming Code Quality in the Worst Language I Know: Bash
 
KWDC 2023-Swift 히스토리 탐방
KWDC 2023-Swift 히스토리 탐방KWDC 2023-Swift 히스토리 탐방
KWDC 2023-Swift 히스토리 탐방
 
Mobile Development integration tests
Mobile Development integration testsMobile Development integration tests
Mobile Development integration tests
 
RESTful API Development using Go
RESTful API Development using GoRESTful API Development using Go
RESTful API Development using Go
 
Web application intro + a bit of ruby (revised)
Web application intro + a bit of ruby (revised)Web application intro + a bit of ruby (revised)
Web application intro + a bit of ruby (revised)
 
Introduction to Ruby Native Extensions and Foreign Function Interface
Introduction to Ruby Native Extensions and Foreign Function InterfaceIntroduction to Ruby Native Extensions and Foreign Function Interface
Introduction to Ruby Native Extensions and Foreign Function Interface
 
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the Rubyist
 
Try! Swift Tokyo2017
Try! Swift Tokyo2017Try! Swift Tokyo2017
Try! Swift Tokyo2017
 
How to build SDKs in Go
How to build SDKs in GoHow to build SDKs in Go
How to build SDKs in Go
 
Swift @ IBM
Swift @ IBMSwift @ IBM
Swift @ IBM
 
RubyMotion Introduction
RubyMotion IntroductionRubyMotion Introduction
RubyMotion Introduction
 
Swimat - Swift formatter
Swimat - Swift formatterSwimat - Swift formatter
Swimat - Swift formatter
 
Introduction to Retrofit
Introduction to RetrofitIntroduction to Retrofit
Introduction to Retrofit
 
Swift 2.2 Design Patterns CocoaConf Austin 2016
Swift 2.2 Design Patterns CocoaConf Austin 2016Swift 2.2 Design Patterns CocoaConf Austin 2016
Swift 2.2 Design Patterns CocoaConf Austin 2016
 

Último

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Último (20)

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
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
  • 4. queue.addOperationWithBlock({ ... }) Inside of □ is a closure argument. Base Syntax of Swift Passing closure argument in parentheses like Objective-C, JavaScript and etc.
  • 5. queue.addOperationWithBlock() { ... } Syntax Sugar of Swift Closure argument go out parentheses of argument list.
  • 6. Syntax Sugar of Swift When other argument is nothing, omission of parentheses is possible. queue.addOperationWithBlock { ... }
  • 7. The person who proposed this syntax surely likes Ruby. Because..
  • 8. block syntax of Ruby queue.addOperationWithBlock do ... end queue.addOperationWithBlock { ... } or
  • 9. block syntax of Ruby queue.addOperationWithBlock { ... } 完全に一致 Completely Match
  • 10. Write your own pseudo syntax sugar
  • 11. In Ruby on Rails app, Podfile of CocoaPods and etc,block syntax of Ruby is used very well.
  • 12. We can do same thing using Swift.
  • 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
  • 14. Pseudo Syntax Sugar delegate method invocation ifRespondTo("cameraPickerDidCancel:") { $0.cameraPickerDidCancel!(self) }
  • 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
  • 16. Pseudo Syntax Sugar (again) delegate method invocation ifRespondTo("cameraPickerDidCancel:") { $0.cameraPickerDidCancel!(self) }
  • 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!
  • 18. 2015/02/15 Swift Developers MeetUp in Tokyo Hisakuni Fujimoto Thank You!