What is swift?
- A new programming language for iOS and OSX app development.
- Adopts modern programming patterns and features to make programming easier and flexible.
- Provides seamless access to existing Cocoa frameworks and mix-and-match interoperability with Objective-C code.
- First industrial-quality systems programming language that is as expressive and enjoyable as a scripting language.
New in swift
- Support for functional programming patterns like maps and filters.
- Structs support protocols, methods and extensions.
- Support for Generics and optionals.
- Support for tuples and hence functions that can return multiple values.
Why use swift?
- About 2.8X faster than objective C.
- A compiled programming language with syntax similar to scripting languages.
- Improved readability over other languages by removing extraneous parenthesis and semi colons.
- Enums and control flows have been vastly improved.
Tools Needed
- Needs Apple LLVM 6.0 for compilation, which is shipped with Xcode 6.0.
- Uses the same runtime as existing Objective-C system on Mac OS and iOS.
- Backward compatible up-to iOS 7.0.
Introduction to “Playground”
- A new type of file that allows you to test out Swift code, and see the results of each line in the sidebar.
- Results appear on the sidebar as soon as any code is typed.
- Great way to learn about Swift, to experiment with new APIs, to prototype code or algorithms.
Objective C Vs Swift
- 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.
- AnyObject: The equivalent of ‘id’ from Objective C, is ‘AnyObject’ in swift.
- Introspection: The equivalent of doing if ([obj isKindOfClass:[NSString class]]) { ... }) in swift is if obj is String.