Swift, a quick overview 
Julian Król 
iOS developer
Notice (!) 
This presentation can be not objective but subjective. 
Any opinions are highly appreciated ;)
General (vital 1/3) 
• no header files for classes, only implementation 
file (one .swift file) 
• no differentiation between ivar and property 
• no need for alloc/init 
• swift can ‘guess’ type of a variable according to 
the object a developer assigns to it (no need for 
an explicit type declaration)
General (vital 2/3) 
! 
• added computed properties (computation at 
calling time) 
• added property observers (you can take some 
action when value changes to different value) 
• added keyword indicating for overriding method 
in subclass
General (vital 3/3) 
• structures can have functions 
• enums are not restricted to represent int values 
• extensions are improvement to categories (you 
can add functionality to structs and primitive 
types) 
• added generics - something like templates in C++
General (very discussable, maybe even not vital) 
• no semicolon at the end of the line 
• less syntax required (example: no need for 
parenthesis in if-statement) 
• easier operations on strings 
• printing to console do not require hard(er) 
formatting
switch statement 
• has to have a default statement 
• case do not need a break statement 
• case value can be whatever developer want 
• switch has to cover all possible values 
(requirement for default case if enlisting is 
impossible)
blocks -> closures 
• a bit easier syntax (block syntax was complex 
from time to time) 
• closures can be seen as unnamed functions 
• variables in closures are not copied but mutable
functions 
• parameter can have a default value (missed that 
when migrated from C++) 
• can return multiple values (I know obj-c can do 
this via arrays dictionaries or any other user’s 
object)
Extensions 
• Swift equivalent to the Objective-C category 
• can add properties but they have to be 
computed one (see other types of properties) 
• can add protocol conformance to a class
Reasons why Swift can 
be a very safe language
Safety 
• arrays can have only one type of objects 
• optionals ‘?’ for marking possibility of receiving/ 
returning a nil value 
• indication for type overflow
Safety 
• if statement has to have curly brackets ‘{}’ 
• switch has to cover all possible values 
• marking overridden functions
Safety 
• id -> AnyObject 
• dealing with unrecognised selector by adding ‘?’ 
to a method call
Comparison in Swift 
• ‘==‘ for objects equality 
• ‘===‘ for objects identity
Comparison in Swift 
• Comparison and Hashable protocols inherits from 
Equatable 
• Equatable needs an implementation of: 
func ==(leftSide: Self, rightSide: Self) -> Bool 
• Hashable needs an implementation of a getter for the 
hashValue property 
• Comparable needs those three: 
func <=(leftSide: Self, rightSide: Self) -> Bool 
func >(leftSide: Self, rightSide: Self) -> Bool 
func >=(leftSide: Self, rightSide: Self) -> Bool
Swift in Objective-C ? 
YES! Possible! It is easy!
Swift in Objective-C 
Swift code prefixed with @objc can be accessed 
from Objective-C code except Swift specific 
features (tuples, generics etc.) 
No need for explicit @objc if Swift class inherits 
from the Objective-C one!
Swift & Objective-C 
Swift class can inherits from Objective-C one but 
not the other way round!
The End 
In case of any suggestion and/or opinion drop me 
an email: viperking@poczta.onet.pl

Swift, a quick overview

  • 1.
    Swift, a quickoverview Julian Król iOS developer
  • 2.
    Notice (!) Thispresentation can be not objective but subjective. Any opinions are highly appreciated ;)
  • 3.
    General (vital 1/3) • no header files for classes, only implementation file (one .swift file) • no differentiation between ivar and property • no need for alloc/init • swift can ‘guess’ type of a variable according to the object a developer assigns to it (no need for an explicit type declaration)
  • 4.
    General (vital 2/3) ! • added computed properties (computation at calling time) • added property observers (you can take some action when value changes to different value) • added keyword indicating for overriding method in subclass
  • 5.
    General (vital 3/3) • structures can have functions • enums are not restricted to represent int values • extensions are improvement to categories (you can add functionality to structs and primitive types) • added generics - something like templates in C++
  • 6.
    General (very discussable,maybe even not vital) • no semicolon at the end of the line • less syntax required (example: no need for parenthesis in if-statement) • easier operations on strings • printing to console do not require hard(er) formatting
  • 7.
    switch statement •has to have a default statement • case do not need a break statement • case value can be whatever developer want • switch has to cover all possible values (requirement for default case if enlisting is impossible)
  • 8.
    blocks -> closures • a bit easier syntax (block syntax was complex from time to time) • closures can be seen as unnamed functions • variables in closures are not copied but mutable
  • 9.
    functions • parametercan have a default value (missed that when migrated from C++) • can return multiple values (I know obj-c can do this via arrays dictionaries or any other user’s object)
  • 10.
    Extensions • Swiftequivalent to the Objective-C category • can add properties but they have to be computed one (see other types of properties) • can add protocol conformance to a class
  • 11.
    Reasons why Swiftcan be a very safe language
  • 12.
    Safety • arrayscan have only one type of objects • optionals ‘?’ for marking possibility of receiving/ returning a nil value • indication for type overflow
  • 13.
    Safety • ifstatement has to have curly brackets ‘{}’ • switch has to cover all possible values • marking overridden functions
  • 14.
    Safety • id-> AnyObject • dealing with unrecognised selector by adding ‘?’ to a method call
  • 15.
    Comparison in Swift • ‘==‘ for objects equality • ‘===‘ for objects identity
  • 16.
    Comparison in Swift • Comparison and Hashable protocols inherits from Equatable • Equatable needs an implementation of: func ==(leftSide: Self, rightSide: Self) -> Bool • Hashable needs an implementation of a getter for the hashValue property • Comparable needs those three: func <=(leftSide: Self, rightSide: Self) -> Bool func >(leftSide: Self, rightSide: Self) -> Bool func >=(leftSide: Self, rightSide: Self) -> Bool
  • 17.
    Swift in Objective-C? YES! Possible! It is easy!
  • 18.
    Swift in Objective-C Swift code prefixed with @objc can be accessed from Objective-C code except Swift specific features (tuples, generics etc.) No need for explicit @objc if Swift class inherits from the Objective-C one!
  • 19.
    Swift & Objective-C Swift class can inherits from Objective-C one but not the other way round!
  • 20.
    The End Incase of any suggestion and/or opinion drop me an email: viperking@poczta.onet.pl