Swift 40
Video: Classes
Classes are general-purpose, flexible constructs that become the building blocks of your program’s code. You define properties and methods to add functionality to your classes by using exactly the same syntax as for constants, variables, and functions.
Unlike other programming languages, Swift does not require you to create separate interface and implementation files for custom classes and structures. In Swift, you define a classin a single file, and the external interface to that class or structure is automatically made available for other code to use.
This video was developed by Skip Wilson. You can follow him on Twitter (@SkipAllMighty).
Video: Structures
Structures are general-purpose, flexible constructs that become the building blocks of your program’s code. You define properties and methods to add functionality to your structures by using exactly the same syntax as for constants, variables, and functions.
Unlike other programming languages, Swift does not require you to create separate interface and implementation files for custom structures. In Swift, you define a structure in a single file, and the external interface to that structure is automatically made available for other code to use.
This video was developed by Skip Wilson. You can follow him on Twitter (@SkipAllMighty).
Video: Functions
Functions are self-contained chunks of code that perform a specific task. You give a function a name that identifies what it does, and this name is used to “call” the function to perform its task when needed.
Swift’s unified function syntax is flexible enough to express anything from a simple C-style function with no parameter names to a complex Objective-C-style method with local and external parameter names for each parameter. Parameters can provide default values to simplify function calls and can be passed as in-out parameters, which modify a passed variable once the function has completed its execution.
Every function in Swift has a type, consisting of the function’s parameter types and return type. You can use this type like any other type in Swift, 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.
This video was developed by Skip Wilson. You can follow him on Twitter (@SkipAllMighty).
Video: Introduction
Swift is a new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun. Swift’s clean slate, backed by the mature and much-loved Cocoa and Cocoa Touch frameworks, is an opportunity to reimagine how software development works.
This video was developed by Skip Wilson. You can follow him on Twitter (@SkipAllMighty).
Say Hello to Swift
One of the biggest announcements coming out of WWDC this year is the creation of a completely new programming language called Swift – the newest programming language used to build apps. Today, most all Apple software is built with Objective-C. Originally designed in the 1980s and soon adopted by Next Computer–the Steve Jobs-led company whose technologies eventually morphed into the modern Mac and the iPhone–the language has ridden these devices to enormous popularity.Apple is wasting no time getting developers educated on the new tools available to them by making The Swift Programming Language guide book immediately available on iTunes. Apple’s new guide offers 500 pages of info on Swift, providing readers with a tour of the new language, along with a detailed guide that dives into each new language feature.
It should feel familiar to those who are already used to Objective-C, Apple says, and is meant to “unify the procedural and object-oriented portions of the language.” It does diverge from Objective-C in more than just the syntax, though; it also features variable types like tuples and optional types. It also includes operators that aren’t found in Objective-C, which allow you to perform remainder operations on floating-point numbers, for example.
Here are some of the highlights of the language according to Apple:
- Closures (similar to blocks in C and Objective-C) unified with function pointers
- Tuples and multiple return values
- Generics
- Fast and concise iteration over a range or collection
- Structs that support methods, extensions, protocols.
- Functional programming patterns, e.g.: map and filter
Objective-C was always a hard language to pick up for new developers. We’ll have to see if Swift makes getting started with app development on Apple’s platforms easier, but from a first look at the documentation, it definitely feels more accessible than Objective-C.
Interactive Playground
On top of this, Apple has added the “interactive playground”, a way of viewing the results of a piece of code as you type it. It reminds me of the Javascript language, trying to make it a more visual endeavor. It’s absolutely amazing. This is the wild card. Depending how well it works, the playground could push mainstream programming in a new direction, providing a more intuitive means of building code. This isn’t necessarily an Apple invention, but it is something that has been bubbling up over the last few years.
But if you put the playground to one side, Swift isn’t really that different from many other languages. It’s mainly a way of bringing Apple’s platform up to par with languages like Ruby and Python–all without sacrificing the speed of Objective-C.
Get Started
Ready to begin? Start with downloading the new XCode 6 Beta from the Apple Developer Portal. Next start reading The Swift Tour and for the best experience open the Guided Tour right in playground, which allows you to edit the code listings and see the results immediately.