What is Swift?
Swift is a powerful programming language developed by Apple, that lets you not only build applications for Apple's platforms, but also do so much more! It supports many different programming paradigms. Swift is the main programming language when building for Apple's platforms. Contrary to popular belief, it is also an open source language, with support for many different kinds of development beyond Apple's Ecosystem.
A Swift History
In 2010 a developer at Apple, Chris Lattner, set out to build a new programming language. Chris wanted to create a new language that could replace the current language Apple relied on, Objective-C. This new language would provide a better developer experience, more safety, and an easier to understand syntax. This work resulted in Swift, and had an initial release in 2014. Since the release Swift has undergone many changes and different versions with continuous improvements on features, speed, and flexibility.
void greet(NSString *name) {
NSLog(@"Hello, %@", name);
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
greet(@"Tiffany");
}
return 0;
}
A greeting program, written in Objective-C
func greet(name: String) {
print("Hello, \(name)")
}
greet("Tiffany")
A greeting program, written in Swift
Compiled vs Interpreted Languages
When learning different programming languages you will find that each one falls into one of two categories: interpreted, or compiled.
Interpreted languages, like JavaScript & Python, use a program called an Interpreter to run their code directly. The interpreter converts the code into something the computer can understand as the program runs. This offers flexibility, but can impact performance and safety.
Compiled languages, like Swift, use a compiler to convert their code into something the computer can understand before the program is run. This allows for typically safer languages, and little to no overhead at runtime. This adds an extra step: you need to compile the code each time you run it.
The Swift compiler provides valuable feedback, catching syntax errors and common bugs before you run the program. The compiler isn't magic and doesn't guarantee error-free code; it only catches certain types of errors. While this step of using a compiler may seem tedious, it ultimately saves you time. Fortunately, the Swift compiler is very fast, minimizing any inconvenience.
Conclusion
Swift offers an amazing developer experience, and is a great language to learn for developers of any experience, whether your first or tenth programming language. It offers a modern, easy to read, safe, and efficient language for building incredible applications of any kind. From its humble origins as a replacement for Objective-C to the open source monster it has become today. Swift provides an excellent foundation for your development journey. Welcome to the world of Swift!