SlideShare a Scribd company logo
1 of 23
Download to read offline
Unit 5—Lesson 1:
Closures
Closures
let sortedTracks = tracks.sorted ( )
(firstTrack: Track, secondTrack: Track) -> Bool in
return firstTrack.trackNumber < secondTrack.trackNumber
Syntax
func sum(numbers: [Int]) -> Int {
// Code that adds together the numbers array
return total
}
let sumClosure = { (numbers: [Int]) -> Int in
// Code that adds together the numbers array
return total
}
// A closure with no parameters and no return value
let printClosure = { () -> Void in
print("This closure does not take any parameters and does not return a value.")
}

// A closure with parameters and no return value
let printClosure = { (string: String) -> Void in
print(string)
}
// A closure with no parameters and a return value
let randomNumberClosure = { () -> Int in
// Code that returns a random number
}
// A closure with parameters and a return value
let randomNumberClosure = { (minValue: Int, maxValue: Int) -> Int in
// Code that returns a random number between `minValue` and `maxValue`
}
Passing closures as arguments
let sortedTracks = tracks.sorted { (firstTrack: Track, secondTrack: Track) -> Bool in
return firstTrack.trackNumber < secondTrack.trackNumber
}
let sortedTracks = tracks.sorted { (firstTrack: Track, secondTrack: Track) -> Bool in
return firstTrack.starRating < secondTrack.starRating
}
Syntactic sugar
let sortedTracks = tracks.sorted { (firstTrack: Track, secondTrack: Track) -> Bool in
return firstTrack.starRating < secondTrack.starRating
}
Syntactic sugar
let sortedTracks = tracks.sorted { (firstTrack, secondTrack) -> Bool in
return firstTrack.starRating < secondTrack.starRating
}
Syntactic sugar
let sortedTracks = tracks.sorted { (firstTrack, secondTrack) in
return firstTrack.starRating < secondTrack.starRating
}
Syntactic sugar
let sortedTracks = tracks.sorted { return $0.starRating < $1.starRating }
Syntactic sugar
let sortedTracks = tracks.sorted { $0.starRating < $1.starRating }
Collection functions using closures
Map

Filter

Reduce
Collection functions using closures
// Initial array
let firstNames = ["Johnny", "Nellie", "Aaron", "Rachel"]
// Creates an empty array that will be used
// to store the full names
var fullNames: [String] = []
for name in firstNames {
let fullName = name + " Smith"
fullNames.append(fullName)
}
0 "Johnny Smith"
1 "Nellie Smith"
2 "Aaron Smith"
3 "Rachel Smith"
fullNames
Collection functions using closures
// Initial array
let firstNames = ["Johnny", "Nellie", "Aaron", "Rachel"]
// Creates a new array of full names by adding "Smith"
// to each first name
let fullNames = firstNames.map { (name) -> String in
return name + " Smith"
}
0 "Johnny Smith"
1 "Nellie Smith"
2 "Aaron Smith"
3 "Rachel Smith"
fullNames
Collection functions using closures
// Initial array
let firstNames = ["Johnny", "Nellie", "Aaron", "Rachel"]
// Creates a new array of full names by adding "Smith"
// to each first name
let fullNames = firstNames.map{ $0 + " Smith" }
0 "Johnny Smith"
1 "Nellie Smith"
2 "Aaron Smith"
3 "Rachel Smith"
fullNames
Collection functions using closures
let numbers = [4, 8, 15, 16, 23, 42]
var numbersLessThan20: [Int] = []
for number in numbers {
if number < 20 {
numbersLessThan20.append(number)
}
}
0 4
1 8
2 15
3 16
numbersLessThan20
Collection functions using closures
let numbers = [4, 8, 15, 16, 23, 42]
let numbersLessThan20 = numbers.filter { (number) -> Bool in
return number < 20
}
0 4
1 8
2 15
3 16
numbersLessThan20
Collection functions using closures
let numbers = [4, 8, 15, 16, 23, 42]
let numbersLessThan20 = numbers.filter{ $0 < 20 }
0 4
1 8
2 15
3 16
numbersLessThan20
Collection functions using closures
let numbers = [8, 6, 7, 5, 3, 0, 9]
var total = 0
for number in numbers {
total = total + number
}
Collection functions using closures
let numbers = [8, 6, 7, 5, 3, 0, 9]
let total = numbers.reduce(0) { (currentTotal, newValue) -> Int in
return currentTotal + newValue
}
Collection functions using closures
let numbers = [8, 6, 7, 5, 3, 0, 9]
let total = numbers.reduce(0,{ $0 + $1})
Closures capture their environment
animate {
self.view.backgroundColor = .red
}
Lab: Closures
Unit 5—Lesson 1
Open and complete the exercises in Lab - Closures.playground
© 2017 Apple Inc. 

This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.

More Related Content

What's hot

Creating a Table from a Function
Creating a Table from a FunctionCreating a Table from a Function
Creating a Table from a Function
dmidgette
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
Anderson Dantas
 

What's hot (20)

Codigos
CodigosCodigos
Codigos
 
Unix prog
Unix progUnix prog
Unix prog
 
Py3k
Py3kPy3k
Py3k
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
Creating a Table from a Function
Creating a Table from a FunctionCreating a Table from a Function
Creating a Table from a Function
 
The Chain Rule, Part 2
The Chain Rule, Part 2The Chain Rule, Part 2
The Chain Rule, Part 2
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practice
 
Slides
SlidesSlides
Slides
 
Python легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиPython легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачи
 
Functional perl
Functional perlFunctional perl
Functional perl
 
Erlang
ErlangErlang
Erlang
 
iRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat SheetiRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat Sheet
 
1 pythonbasic
1 pythonbasic1 pythonbasic
1 pythonbasic
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
PHP 101
PHP 101 PHP 101
PHP 101
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with Python
 
Analytics functions in mysql, oracle and hive
Analytics functions in mysql, oracle and hiveAnalytics functions in mysql, oracle and hive
Analytics functions in mysql, oracle and hive
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 redux
 
Lecture5 my sql statements by okello erick
Lecture5 my sql statements by okello erickLecture5 my sql statements by okello erick
Lecture5 my sql statements by okello erick
 

Similar to Closures

Problem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdfProblem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdf
ebrahimbadushata00
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
Rahul04August
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
arri2009av
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
Ian Bishop
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
riue
 
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
anujsharmaanuj14
 

Similar to Closures (20)

Problem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdfProblem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdf
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Swift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfSwift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdf
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
Parameters
ParametersParameters
Parameters
 
Hitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingHitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional Programming
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
 
Arrow 101 - Kotlin funcional com Arrow
Arrow 101 - Kotlin funcional com ArrowArrow 101 - Kotlin funcional com Arrow
Arrow 101 - Kotlin funcional com Arrow
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
 
Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collections
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
 
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!
 

More from SV.CO (20)

Handout level-1-module-1
Handout   level-1-module-1Handout   level-1-module-1
Handout level-1-module-1
 
Persistence And Documents
Persistence And DocumentsPersistence And Documents
Persistence And Documents
 
Building complex input screens
Building complex input screensBuilding complex input screens
Building complex input screens
 
Working with the Web: 
Decoding JSON
Working with the Web: 
Decoding JSONWorking with the Web: 
Decoding JSON
Working with the Web: 
Decoding JSON
 
Saving Data
Saving DataSaving Data
Saving Data
 
Alerts notification
Alerts notificationAlerts notification
Alerts notification
 
UI Dynamics
UI DynamicsUI Dynamics
UI Dynamics
 
Practical animation
Practical animationPractical animation
Practical animation
 
Segues and navigation controllers
Segues and navigation controllersSegues and navigation controllers
Segues and navigation controllers
 
Camera And Email
Camera And EmailCamera And Email
Camera And Email
 
Scroll views
Scroll viewsScroll views
Scroll views
 
Intermediate table views
Intermediate table viewsIntermediate table views
Intermediate table views
 
Table views
Table viewsTable views
Table views
 
Protocols
ProtocolsProtocols
Protocols
 
App anatomy and life cycle
App anatomy and life cycleApp anatomy and life cycle
App anatomy and life cycle
 
Extensions
ExtensionsExtensions
Extensions
 
Gestures
GesturesGestures
Gestures
 
View controller life cycle
View controller life cycleView controller life cycle
View controller life cycle
 
Controls in action
Controls in actionControls in action
Controls in action
 
Auto layout and stack views
Auto layout and stack viewsAuto layout and stack views
Auto layout and stack views
 

Recently uploaded

Recently uploaded (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

Closures

  • 2. Closures let sortedTracks = tracks.sorted ( ) (firstTrack: Track, secondTrack: Track) -> Bool in return firstTrack.trackNumber < secondTrack.trackNumber
  • 3. Syntax func sum(numbers: [Int]) -> Int { // Code that adds together the numbers array return total } let sumClosure = { (numbers: [Int]) -> Int in // Code that adds together the numbers array return total }
  • 4. // A closure with no parameters and no return value let printClosure = { () -> Void in print("This closure does not take any parameters and does not return a value.") }
 // A closure with parameters and no return value let printClosure = { (string: String) -> Void in print(string) } // A closure with no parameters and a return value let randomNumberClosure = { () -> Int in // Code that returns a random number } // A closure with parameters and a return value let randomNumberClosure = { (minValue: Int, maxValue: Int) -> Int in // Code that returns a random number between `minValue` and `maxValue` }
  • 5. Passing closures as arguments let sortedTracks = tracks.sorted { (firstTrack: Track, secondTrack: Track) -> Bool in return firstTrack.trackNumber < secondTrack.trackNumber } let sortedTracks = tracks.sorted { (firstTrack: Track, secondTrack: Track) -> Bool in return firstTrack.starRating < secondTrack.starRating }
  • 6. Syntactic sugar let sortedTracks = tracks.sorted { (firstTrack: Track, secondTrack: Track) -> Bool in return firstTrack.starRating < secondTrack.starRating }
  • 7. Syntactic sugar let sortedTracks = tracks.sorted { (firstTrack, secondTrack) -> Bool in return firstTrack.starRating < secondTrack.starRating }
  • 8. Syntactic sugar let sortedTracks = tracks.sorted { (firstTrack, secondTrack) in return firstTrack.starRating < secondTrack.starRating }
  • 9. Syntactic sugar let sortedTracks = tracks.sorted { return $0.starRating < $1.starRating }
  • 10. Syntactic sugar let sortedTracks = tracks.sorted { $0.starRating < $1.starRating }
  • 11. Collection functions using closures Map Filter Reduce
  • 12. Collection functions using closures // Initial array let firstNames = ["Johnny", "Nellie", "Aaron", "Rachel"] // Creates an empty array that will be used // to store the full names var fullNames: [String] = [] for name in firstNames { let fullName = name + " Smith" fullNames.append(fullName) } 0 "Johnny Smith" 1 "Nellie Smith" 2 "Aaron Smith" 3 "Rachel Smith" fullNames
  • 13. Collection functions using closures // Initial array let firstNames = ["Johnny", "Nellie", "Aaron", "Rachel"] // Creates a new array of full names by adding "Smith" // to each first name let fullNames = firstNames.map { (name) -> String in return name + " Smith" } 0 "Johnny Smith" 1 "Nellie Smith" 2 "Aaron Smith" 3 "Rachel Smith" fullNames
  • 14. Collection functions using closures // Initial array let firstNames = ["Johnny", "Nellie", "Aaron", "Rachel"] // Creates a new array of full names by adding "Smith" // to each first name let fullNames = firstNames.map{ $0 + " Smith" } 0 "Johnny Smith" 1 "Nellie Smith" 2 "Aaron Smith" 3 "Rachel Smith" fullNames
  • 15. Collection functions using closures let numbers = [4, 8, 15, 16, 23, 42] var numbersLessThan20: [Int] = [] for number in numbers { if number < 20 { numbersLessThan20.append(number) } } 0 4 1 8 2 15 3 16 numbersLessThan20
  • 16. Collection functions using closures let numbers = [4, 8, 15, 16, 23, 42] let numbersLessThan20 = numbers.filter { (number) -> Bool in return number < 20 } 0 4 1 8 2 15 3 16 numbersLessThan20
  • 17. Collection functions using closures let numbers = [4, 8, 15, 16, 23, 42] let numbersLessThan20 = numbers.filter{ $0 < 20 } 0 4 1 8 2 15 3 16 numbersLessThan20
  • 18. Collection functions using closures let numbers = [8, 6, 7, 5, 3, 0, 9] var total = 0 for number in numbers { total = total + number }
  • 19. Collection functions using closures let numbers = [8, 6, 7, 5, 3, 0, 9] let total = numbers.reduce(0) { (currentTotal, newValue) -> Int in return currentTotal + newValue }
  • 20. Collection functions using closures let numbers = [8, 6, 7, 5, 3, 0, 9] let total = numbers.reduce(0,{ $0 + $1})
  • 21. Closures capture their environment animate { self.view.backgroundColor = .red }
  • 22. Lab: Closures Unit 5—Lesson 1 Open and complete the exercises in Lab - Closures.playground
  • 23. © 2017 Apple Inc. This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.