2. Notice (!)
This presentation 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
• 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)
10. 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
12. Safety
• arrays can have only one type of objects
• optionals ‘?’ for marking possibility of receiving/
returning a nil value
• indication for type overflow
13. Safety
• if statement 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
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
In case of any suggestion and/or opinion drop me
an email: viperking@poczta.onet.pl