Sunday 28 February 2016

Introduction to SWIFT


Introduction to SWIFT

 A modern programming language that is safe, fast, and interactive,Swift is a powerful and intuitive programming language for iOS, OS X, tvOS, and watchOS. Writing Swift code is interactive and fun, the syntax is concise yet expressive, and apps run lightning-fast. Swift is ready for your next project — or addition into your current app — because Swift code works side-by-side with Objective-C.The Swift compiler is faster then Objective-C compiler 
  • Error handling
  • Syntax improvements
  • Open source
  • Modern
  • Designed for safety
  • Fast and Powerful
  • Objective-C interoperability

Error handling model

An advanced error handling model provides clear, expressive syntax for catching and throwing errors. It’s also easy to create your own custom error types so you can describe error cases with clear, meaningful names. The new error model was designed to work seamlessly with NSError and the Cocoa frameworks. Error handling code now looks like:

Syntax improvements

  1. Powerful control flow with doguarddefer, and repeat
  2. Keyword naming rules unified for functions and methods
  3. Protocol extensions and default implementations
  4. Extended pattern matching to work in if clauses and for loops

Open Source

Swift is developed in the open at Swift.org, with source code, a bug tracker, mailing lists, and regular development builds available for everyone. The broad community of developers, both inside and outside of Apple, are working together to make Swift even more amazing. Swift already has support for all Apple platforms as well as Linux, with new platforms to come.

Modern

Swift is the result of the latest research on programming languages, combined with decades of experience building Apple platforms. Named parameters brought forward from Objective-C are expressed in a clean syntax that makes APIs in Swift even easier to read and maintain.

Swift has many other features to make your code more expressive:

  • Closures unified with function pointers
  • Tuples and multiple return values
  • Generics
  • Fast and concise iteration over a range or collection
  • Structs that support methods, extensions, and protocols
  • Functional programming patterns, e.g., map and filter
  • Native error handling using try / catch / throw

Designed for Safety

Swift eliminates entire classes of unsafe code. Variables are always initialized before use, arrays and integers are checked for overflow, and memory is managed automatically. Syntax is tuned to make it easy to define your intent — for example, simple three-character keywords define a variable ( var ) or constant ( let ).

Another safety feature is that by default Swift objects can never benil. In fact, the Swift compiler will stop you from trying to make or use a nil object with a compile-time error. This makes writing code much cleaner and safer, and prevents a huge category of runtime crashes in your apps. However, there are cases where nil is valid and appropriate. For these situations Swift has an innovative feature known as optionals. An optional may contain nil, but Swift syntax forces you to safely deal with it using the ? syntax to indicate to the compiler you understand the behavior and will handle it safely

Fast and Powerful

From its earliest conception, Swift was built to be fast. Using the incredibly high-performance LLVM compiler, Swift code is transformed into optimized native code that gets the most out of modern hardware. The syntax and standard library have also been tuned to make the most obvious way to write your code also perform the best

Objective-C Interoperability

You can create an entirely new application with Swift today, or begin using Swift code to implement new features in your app, or enhance existing ones. Swift code co-exists along side your existing Objective-C files in the same project, with full access to your Objective-C API, making it easy to adopt.