Swift is a new programming language developed by Apple Inc. The swift was released in 2010 by Chris Lattner. Swift uses the modern programming language structures and it is same as objective c like syntax. You can create iOS, OS X applications with Swift programming language. Swift comes with Playground to write their swift program and the output is displayed in right side. It shows the results very fast and you no need to click any run buttons to execute the program. It is very interesting know ? Swift has a lot of features and it has a huge libraries too. The extension of swift program is .swift.
Swift Playground is only for learning purposes and to write swift program you need to install Xcode on your Mac OS. To install Xcode, you wanna create an account at Apple Developer site and then download the Xcode or else you can download it from Mac AppStore itself. Just search for "Xcode" in the search bar on top right corner of AppStore. Once you installed, then open it and select Get started with a playground and give name to the playground. Then select iOS as platform now you'll get the playground and then you can start write your swift code.
For iOS, You've to import UIKit
For OS X, You've to import Cocoa
It starts with // and followed by some characters
Swift Playground is only for learning purposes and to write swift program you need to install Xcode on your Mac OS. To install Xcode, you wanna create an account at Apple Developer site and then download the Xcode or else you can download it from Mac AppStore itself. Just search for "Xcode" in the search bar on top right corner of AppStore. Once you installed, then open it and select Get started with a playground and give name to the playground. Then select iOS as platform now you'll get the playground and then you can start write your swift code.
Let's get started with simple swift code.
For iOS, You've to import UIKit
import UIKit var stringVal = "Hello World"
For OS X, You've to import Cocoa
import Cocoa var stringVal = "Hello World"
In both program, you'll get the Hello World as output in right side of the playground. It's pretty awesome know ? You're getting your results without clicking any run button. Playground is really a good one to learn swift. Finally you've created your first swift program :)
Imports statement
In swift, you've to use import keyword to import any Objective C framework in the swift program.
Tokens
Token is same as in other programming languages like C,C++ and Java etc. Token is a keyword, identifier, constants, symbols etc. You can see many tokens in a small piece of swift code.
For ex : print,import.
For ex : print,import.
Identifiers
Identifier is the name used for naming the variables, functions etc. Identifier starts with an alphabets from A to Z(uppercase) or a to z(lowercase) or starts with underscore symbol with some characters and numbers.
Comments
Comments are mainly useful for developers to understand the code. It is ignored by the compiler while executing the code. Two types of comments used in the swift programming language.
For ex : In app development, the developers will write comments above the code to understand the logic.
Types :
1. Single Line Comment
2. Multi Line Comment
Single Line Comment:
It starts with // and followed by some characters
// This is swift programming language
Multi Line Comment:
It starts with /* and followed by some characters and then it ends with */
/* This is swift programming language Hello Swift developers */
Keywords
Keywords are predefined words in swift. So you don't use these words to create variables, constants and functions etc.
Ex : class, public, private, var, do, nil, self, if, break, func, init, internal and so on.
Ex : class, public, private, var, do, nil, self, if, break, func, init, internal and so on.
Swift is the alternative programming language for objective c and swift is the future programming language to write iOS and OS X apps. I hope now you'll came to know about swift. In next tutorial, we'll see about the usage of variables, constants etc
Happy Coding...
Happy Coding...
No comments:
Post a Comment