SlideShare a Scribd company logo
1 of 5
Download to read offline
Apple’s New Swift Programming
Language Takes Flight With New
Enhancements And Features
Recently Apple team has released Swift 1.2 as a part of Xcode 6.3 beta. Beta release includes
a significantly enhanced swift compiler and as well as new features in the Swift language.
Apples team has came up with improvements in compiler and new language features in Swift
1.2 beta release ,let’s dive into improvements in Swift language
Compiler Enhancements:
Apple team has come up with enhancements in compiler to be more stable and improved
performance in every aspect. By these enhancements developer can see an better
experience when working with Swift in X- code , some of the most visible enhancements
includes are:
• Incremental Builds — Source files that haven’t changed will no longer be re-compiled by
default, which will significantly improve build times for most common cases. Larger
structural changes to your code may still require multiple files to be rebuilt.
• Faster Executables — Debug builds produce binaries that run considerably faster, and new
optimizations deliver even better Release build performance.
• Better Compiler Diagnostics — Clearer error and warning messages, along with new Fix-
its, make it easier to write proper Swift 1.2 code.
• Stability Improvements — The most common compiler crashes have been fixed. You
should also see fewer SourceKit warnings within the Xcode editor.
Enhancements and Features:
Let’s take a look on enhancements and new features introduced in Swift language to
overcome cons of Objective-C. In Swift language , Function has come up with enhancements
like ability to return multiple values , nested functions etc. Swift’s unified functions syntax is
flexible enough to express anything fro simple C-style function with no parameter names to a
complex Objective-C-style method with local and external parameter names for each
parameter. Every function in Swift has a type, consisting of the function’s parameter types
and return type, which makes it easy to pass functions as parameters to other functions, and
to return functions from functions. Functions can also be written within other functions to
encapsulate useful functionality within a nested function scope.
Simple example of function with multiple input parameters:
Functions can have multiple input parameters, which are written within the function’s
parentheses, separated by commas.
This function takes a start and an end index for a half-open range, and works out how many
elements the range contains:
1
2
3
4
5
6
7
8
9
func halfOpenRangeLength(start: Int, end: Int) -> Int {
return end - start
}
println(halfOpenRangeLength(1, 10))
// prints "9"
Closures: Closures are self-contained blocks of functionality that can be passed around and
used in your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas
in other programming languages. Closures can capture and store references to any constants
and variables from the context in which they are defined. In Swift, the simplest form of a
closure that can capture values is a nested function, written within the body of another
function. A nested function can capture any of its outer function’s arguments and can also
capture any constants and variables defined within the outer function.
Here’s an example of a function called makeIncrementer, which contains a nested function
called incrementer. The nested incrementer function captures two
values, runningTotal and amount, from its surrounding context. After capturing these
values, incrementer is returned by makeIncrementer as a closure that incrementsrunning
Total by amount each time it is called.
1
2
3
4
5
6
7
8
9
10
11
func makeIncrementer(forIncrement amount: Int) -> () -> Int {
var runningTotal = 0
func incrementer() -> Int {
runningTotal += amount
return runningTotal
}
Enumerations: Enumerations in Swift are first-class types in their own right. They adopt
many features traditionally supported only by classes. Enumerations can also define
initializers to provide an initial member value; can be extended to expand their functionality
beyond their original implementation; and can conform to protocols to provide standard
functionality.
You introduce enumerations with the enum keyword and place their entire definition
within a pair of braces:
1
2
3
4
5
enum SomeEnumeration {
// enumeration definition goes here
}
Multiple member values can appear on a single line, separated by commas:
1
2
3
4
5
enum Planet {
case Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
}
Generics: Generics are one of the most powerful features of Swift, and much of the Swift
standard library is built with generic code. Generic code enables you to write flexible, reusable
functions and types that can work with any type, subject to requirements that you define.
You can write code that avoids duplication and expresses its intent in a clear, abstracted
manner.
More powerful optional unwrapping with if let — The if let construct can now unwrap
multiple optional at once, as well as include intervening boolean conditions. This lets you
express conditional control flow without unnecessary nesting.
New native Set data structure — An unordered collection of unique elements that bridges
withNSSet and provides value semantics like Array and Dictionary.
Nullability may now be expressed in Objective-C headers — New Objective-C extensions in
Clang allow you to express the nullability of pointers and blocks in your Objective-C API. You
can provide Objective-C frameworks that work great with Swift code, and improve your
Swift experience when mixing and matching with Objective-C code in your own project.
Apple’s New Swift Programming Language Takes Flight With New Enhancements And Features

More Related Content

What's hot

Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
Deepak Singh
 

What's hot (20)

Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Java script function
Java script functionJava script function
Java script function
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
 
Pluggable Pipelines
Pluggable PipelinesPluggable Pipelines
Pluggable Pipelines
 
Basics1
Basics1Basics1
Basics1
 
over all view programming to computer
over all view programming to computer over all view programming to computer
over all view programming to computer
 
JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 
Vb
VbVb
Vb
 
Differences between method overloading and method overriding
Differences between method overloading and method overridingDifferences between method overloading and method overriding
Differences between method overloading and method overriding
 
Handout # 4 functions + scopes
Handout # 4   functions + scopes Handout # 4   functions + scopes
Handout # 4 functions + scopes
 
Advanced Java Topics
Advanced Java TopicsAdvanced Java Topics
Advanced Java Topics
 
Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript Fundamentals
 
General structure of c++
General structure of c++General structure of c++
General structure of c++
 
Unit 3
Unit 3Unit 3
Unit 3
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
 
Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013
 

Viewers also liked

Marcus James CV 2016
Marcus James CV 2016Marcus James CV 2016
Marcus James CV 2016
Marcus James
 
Solve Quad Graph Calc.pdf
Solve Quad Graph Calc.pdfSolve Quad Graph Calc.pdf
Solve Quad Graph Calc.pdf
bwlomas
 
Dispositivos de almacenamiento
Dispositivos de almacenamientoDispositivos de almacenamiento
Dispositivos de almacenamiento
Anna Melissa
 
Danforth Bus Cards
Danforth Bus CardsDanforth Bus Cards
Danforth Bus Cards
Rick Bunting
 
Grom Capabilities 2016
Grom Capabilities 2016Grom Capabilities 2016
Grom Capabilities 2016
Sue Linder
 
Municipal OWI Prosecution
Municipal OWI ProsecutionMunicipal OWI Prosecution
Municipal OWI Prosecution
Douglas Hoffer
 
Creating spaces for learning. Designing the UCD Health Sciences Library ASME ...
Creating spaces for learning. Designing the UCD Health Sciences Library ASME ...Creating spaces for learning. Designing the UCD Health Sciences Library ASME ...
Creating spaces for learning. Designing the UCD Health Sciences Library ASME ...
Peter Hickey
 

Viewers also liked (19)

Marcus James CV 2016
Marcus James CV 2016Marcus James CV 2016
Marcus James CV 2016
 
Solve Quad Graph Calc.pdf
Solve Quad Graph Calc.pdfSolve Quad Graph Calc.pdf
Solve Quad Graph Calc.pdf
 
Dispositivos de almacenamiento
Dispositivos de almacenamientoDispositivos de almacenamiento
Dispositivos de almacenamiento
 
3dd
3dd3dd
3dd
 
Code Resume
Code ResumeCode Resume
Code Resume
 
Danforth Bus Cards
Danforth Bus CardsDanforth Bus Cards
Danforth Bus Cards
 
Resumo t3 lengua_6
Resumo t3 lengua_6Resumo t3 lengua_6
Resumo t3 lengua_6
 
Grom Capabilities 2016
Grom Capabilities 2016Grom Capabilities 2016
Grom Capabilities 2016
 
Municipal OWI Prosecution
Municipal OWI ProsecutionMunicipal OWI Prosecution
Municipal OWI Prosecution
 
Creating spaces for learning. Designing the UCD Health Sciences Library ASME ...
Creating spaces for learning. Designing the UCD Health Sciences Library ASME ...Creating spaces for learning. Designing the UCD Health Sciences Library ASME ...
Creating spaces for learning. Designing the UCD Health Sciences Library ASME ...
 
JoshStuckeyResume
JoshStuckeyResumeJoshStuckeyResume
JoshStuckeyResume
 
Klsmsithportfolio
KlsmsithportfolioKlsmsithportfolio
Klsmsithportfolio
 
Psicologia de la Gestalt
Psicologia de la GestaltPsicologia de la Gestalt
Psicologia de la Gestalt
 
R2 lengua 6
R2 lengua 6R2 lengua 6
R2 lengua 6
 
ESPA 2014-2020_Yfistamenes parousiash
ESPA 2014-2020_Yfistamenes parousiashESPA 2014-2020_Yfistamenes parousiash
ESPA 2014-2020_Yfistamenes parousiash
 
El Reina Ana en medio de una Tormenta
El Reina Ana en medio de una TormentaEl Reina Ana en medio de una Tormenta
El Reina Ana en medio de una Tormenta
 
Anatomy of a connected product
Anatomy of a connected productAnatomy of a connected product
Anatomy of a connected product
 
Marea neagră
Marea neagrăMarea neagră
Marea neagră
 
meldung.pdf
meldung.pdfmeldung.pdf
meldung.pdf
 

Similar to Apple’s New Swift Programming Language Takes Flight With New Enhancements And Features

C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
techfreak
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming379008-rc217-functionalprogramming
379008-rc217-functionalprogramming
Luis Atencio
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 

Similar to Apple’s New Swift Programming Language Takes Flight With New Enhancements And Features (20)

Swift programming language
Swift programming languageSwift programming language
Swift programming language
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
 
Introduction of C++ By Pawan Thakur
Introduction of C++ By Pawan ThakurIntroduction of C++ By Pawan Thakur
Introduction of C++ By Pawan Thakur
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java script
 
Opps concept
Opps conceptOpps concept
Opps concept
 
C# Unit 1 notes
C# Unit 1 notesC# Unit 1 notes
C# Unit 1 notes
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
 
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming379008-rc217-functionalprogramming
379008-rc217-functionalprogramming
 
C programming course material
C programming course materialC programming course material
C programming course material
 
Unit1 cd
Unit1 cdUnit1 cd
Unit1 cd
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 

More from Azilen Technologies Pvt. Ltd.

More from Azilen Technologies Pvt. Ltd. (20)

Software Product Development for Startups.pdf
Software Product Development for Startups.pdfSoftware Product Development for Startups.pdf
Software Product Development for Startups.pdf
 
How Chatbots Empower Healthcare Ecosystem?
How Chatbots Empower Healthcare Ecosystem?How Chatbots Empower Healthcare Ecosystem?
How Chatbots Empower Healthcare Ecosystem?
 
[Step by-step guide] configure document generation functionality in ms dynami...
[Step by-step guide] configure document generation functionality in ms dynami...[Step by-step guide] configure document generation functionality in ms dynami...
[Step by-step guide] configure document generation functionality in ms dynami...
 
How to overcome operational challenges in getting consistent beacon behavior
How to overcome operational challenges in getting consistent beacon behaviorHow to overcome operational challenges in getting consistent beacon behavior
How to overcome operational challenges in getting consistent beacon behavior
 
Liferay dxp – the good, the bad and the ugly
Liferay dxp – the good, the bad and the uglyLiferay dxp – the good, the bad and the ugly
Liferay dxp – the good, the bad and the ugly
 
Realm mobile platform – explore real time data synchronization capabilities
Realm mobile platform – explore real time data synchronization capabilitiesRealm mobile platform – explore real time data synchronization capabilities
Realm mobile platform – explore real time data synchronization capabilities
 
A step by step guide to develop temperature sensor io t application using ibm...
A step by step guide to develop temperature sensor io t application using ibm...A step by step guide to develop temperature sensor io t application using ibm...
A step by step guide to develop temperature sensor io t application using ibm...
 
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
 
Register Virtual Device and analyze the device data
Register Virtual Device and analyze the device dataRegister Virtual Device and analyze the device data
Register Virtual Device and analyze the device data
 
Analytics and etl based bi solutions
Analytics and etl based bi solutionsAnalytics and etl based bi solutions
Analytics and etl based bi solutions
 
Advanced risk management & mitigation system
Advanced risk management & mitigation systemAdvanced risk management & mitigation system
Advanced risk management & mitigation system
 
Server driven user interface (sdui) – framework for i os applications!
Server driven user interface (sdui) – framework for i os applications!Server driven user interface (sdui) – framework for i os applications!
Server driven user interface (sdui) – framework for i os applications!
 
How to integrate portlet as widget in liferay to any website application
How to integrate portlet as widget in liferay to any website applicationHow to integrate portlet as widget in liferay to any website application
How to integrate portlet as widget in liferay to any website application
 
A walkthrough of recently held wwdc17
A walkthrough of recently held wwdc17A walkthrough of recently held wwdc17
A walkthrough of recently held wwdc17
 
How wearable devices are changing our lives
How wearable devices are changing our livesHow wearable devices are changing our lives
How wearable devices are changing our lives
 
iPad Application as Return Process Automation Solution for eCommerce Store
iPad Application as Return Process Automation Solution for eCommerce StoreiPad Application as Return Process Automation Solution for eCommerce Store
iPad Application as Return Process Automation Solution for eCommerce Store
 
[Part 3] automation of home appliances using raspberry pi – all set to automa...
[Part 3] automation of home appliances using raspberry pi – all set to automa...[Part 3] automation of home appliances using raspberry pi – all set to automa...
[Part 3] automation of home appliances using raspberry pi – all set to automa...
 
Rfid systems for asset management — the young technology on its winning path
Rfid systems for asset management — the young technology on its winning pathRfid systems for asset management — the young technology on its winning path
Rfid systems for asset management — the young technology on its winning path
 
[Part 2] automation of home appliances using raspberry pi – implementation of...
[Part 2] automation of home appliances using raspberry pi – implementation of...[Part 2] automation of home appliances using raspberry pi – implementation of...
[Part 2] automation of home appliances using raspberry pi – implementation of...
 
[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

Apple’s New Swift Programming Language Takes Flight With New Enhancements And Features

  • 1. Apple’s New Swift Programming Language Takes Flight With New Enhancements And Features Recently Apple team has released Swift 1.2 as a part of Xcode 6.3 beta. Beta release includes a significantly enhanced swift compiler and as well as new features in the Swift language. Apples team has came up with improvements in compiler and new language features in Swift 1.2 beta release ,let’s dive into improvements in Swift language Compiler Enhancements: Apple team has come up with enhancements in compiler to be more stable and improved performance in every aspect. By these enhancements developer can see an better experience when working with Swift in X- code , some of the most visible enhancements includes are: • Incremental Builds — Source files that haven’t changed will no longer be re-compiled by default, which will significantly improve build times for most common cases. Larger structural changes to your code may still require multiple files to be rebuilt. • Faster Executables — Debug builds produce binaries that run considerably faster, and new optimizations deliver even better Release build performance.
  • 2. • Better Compiler Diagnostics — Clearer error and warning messages, along with new Fix- its, make it easier to write proper Swift 1.2 code. • Stability Improvements — The most common compiler crashes have been fixed. You should also see fewer SourceKit warnings within the Xcode editor. Enhancements and Features: Let’s take a look on enhancements and new features introduced in Swift language to overcome cons of Objective-C. In Swift language , Function has come up with enhancements like ability to return multiple values , nested functions etc. Swift’s unified functions syntax is flexible enough to express anything fro simple C-style function with no parameter names to a complex Objective-C-style method with local and external parameter names for each parameter. Every function in Swift has a type, consisting of the function’s parameter types and return type, which makes it easy to pass functions as parameters to other functions, and to return functions from functions. Functions can also be written within other functions to encapsulate useful functionality within a nested function scope. Simple example of function with multiple input parameters: Functions can have multiple input parameters, which are written within the function’s parentheses, separated by commas. This function takes a start and an end index for a half-open range, and works out how many elements the range contains: 1 2 3 4 5 6 7 8 9 func halfOpenRangeLength(start: Int, end: Int) -> Int { return end - start } println(halfOpenRangeLength(1, 10)) // prints "9" Closures: Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas in other programming languages. Closures can capture and store references to any constants and variables from the context in which they are defined. In Swift, the simplest form of a closure that can capture values is a nested function, written within the body of another function. A nested function can capture any of its outer function’s arguments and can also capture any constants and variables defined within the outer function.
  • 3. Here’s an example of a function called makeIncrementer, which contains a nested function called incrementer. The nested incrementer function captures two values, runningTotal and amount, from its surrounding context. After capturing these values, incrementer is returned by makeIncrementer as a closure that incrementsrunning Total by amount each time it is called. 1 2 3 4 5 6 7 8 9 10 11 func makeIncrementer(forIncrement amount: Int) -> () -> Int { var runningTotal = 0 func incrementer() -> Int { runningTotal += amount return runningTotal } Enumerations: Enumerations in Swift are first-class types in their own right. They adopt many features traditionally supported only by classes. Enumerations can also define initializers to provide an initial member value; can be extended to expand their functionality beyond their original implementation; and can conform to protocols to provide standard functionality. You introduce enumerations with the enum keyword and place their entire definition within a pair of braces: 1 2 3 4 5 enum SomeEnumeration { // enumeration definition goes here } Multiple member values can appear on a single line, separated by commas: 1 2 3 4 5 enum Planet { case Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune } Generics: Generics are one of the most powerful features of Swift, and much of the Swift standard library is built with generic code. Generic code enables you to write flexible, reusable functions and types that can work with any type, subject to requirements that you define. You can write code that avoids duplication and expresses its intent in a clear, abstracted manner. More powerful optional unwrapping with if let — The if let construct can now unwrap
  • 4. multiple optional at once, as well as include intervening boolean conditions. This lets you express conditional control flow without unnecessary nesting. New native Set data structure — An unordered collection of unique elements that bridges withNSSet and provides value semantics like Array and Dictionary. Nullability may now be expressed in Objective-C headers — New Objective-C extensions in Clang allow you to express the nullability of pointers and blocks in your Objective-C API. You can provide Objective-C frameworks that work great with Swift code, and improve your Swift experience when mixing and matching with Objective-C code in your own project.