Swift is an object oriented programming language from Apple targeted primarily for iOS, MacOSX, tvOS,
watchOS application development. Swift is general purpose programming language and it is open source.
It is modern, safe, fast.
- Syntax is very similar to many available scripting languages specially java script, so easy to adopt / learn.
- No pointers, no direct memory access
- ARC(Automatic reference counting) for memory management. It's simple and fast than garbage collector.
- Inter-operability, mix and match to work smoothly with older libraries already written in objective c and tested well.
- Modern features like closures (lambda/block) in other programming language.
- Open source programming language, available on MacOSX and Linux
Since swift is primarily used on Apple platform like Mac OSX desktop applications, iOS application,
watchOS, tvOS etc, so we will focus our tutorial in line with Xcode editor and MacOSX/iOS application
You can get Xcode from Apple's App Store.
- Launch App Store
- Search for Xcode on App Store
- Install Xcode
Xcode installation is very easy. App Store app does everything itself once you click on install
button next to Xcode icon as shown in above screenshot. You might have to authenticate your download
against your App Store credentials.
First Swift Program: "Hello World"
Launch Xcode on your mac.
Create new Xcode project.
Select command line project in MacOS X environment as shown in this pic.
Select the programming language as Swift and provide your "Product Name".
Lets give Product Name as "HelloWorld" as shown in screenshot. Then go ahead and save
the project on your mac [may be in Document folder or on Desktop].
On completion of last step, you will see there are some files created for you and in
left column which is project navigator the files are listed. Click on main.m and you will
see some code pre-written for you. At this point you are actually done with your first project "HelloWorld",
the wizard has created it everything for you and now you have to Run the App to see the output.
See the output in console as shown in below screenshot.