Swift programming language

0
111
Swift programming language
Swift programming language

Swift programming language: This robust programming language will work faster than Objective-C and can be easily learned. Apple says programmers will be able to write more secure and reliable code using Swift. It allows programmers to write code at the same time to see its output Swift is as powerful and compliant as compiled languages, while simple and interactive like popular scripting languages. Using Swift, programmers can easily develop iOS applications. Apple has created a 500-page book for the Swift language. This book is available at Apple’s own ibook store. Link: https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11 .

Swift is Apple’s programming language, Apple’s surprise. Earlier, the empire was ruled by C. Swift has already begun to reign. Swift is a Fast, Modern, Safe and Interactive Object Oriented Programming Language. The syntax is very simple and beautiful. Now only Mac users can write code in Swift.

I have written some very basic articles here. To work with Swift, you must first download the Xcode. You can go to the App Store and download Xcode. Once installed we are ready to write our first Swift program.

Those who do not have a Mac [OS X], but are interested in learning Swift,   can go to the online.swiftplayground.run the site and run the code to see the results. Learning will be done.

When you open Xcode, it will look like below.

From here I will click on Get started with a playground. Then you will be asked to select a template. I will select the blank template and click on next. And In the end I will create a playground file with a name. Write the initial code for us:

Clicking the play button at the bottom will run the file. The right side will show the output. This is it. Welcome to Swift!

Hello, World program in Swift language:

Let’s open a new project in XCode. How to open the Object-C and iPhone development project, Swift has to open the project simultaneously. All you have to do is open the Playground type project first and select “swift” from the language list. This facility will be available from XCode.

So let’s write the Hello World program in Swift language

println("Hello, World")

By just typing in the original file of the newly created project, you will see “Hello, world” in the output window on the right.

Library Import ( Swift Language ) program also requires an external library to be imported into the project. Importing a library is only by entering the name of the library with import.

import Foundation

println("Foundation Library is imported.");

Variables, Constants and Type Annotations:

Declaring variables or constants like Objective-C does not require the actual datatype to be written in Swift. In Swift, only “var” is used to declare variables and “let” is used to declare a constant. The advantage is that there is no need to worry about its datatype when declaring a variable or constant. The type of data that will be initialized, their datatype and so on. It will be clear when you see your own program.

println("Hello, world")
 var myVariable = 42
 // myVariable is a variable which will be inferred to be int
 var (x, y, z) = (11, 12, 45)                      // x = 11, y = 12, z = 45
 // x, y and z variables are inferred to be int
 let π = 3.1415926                                 // constant
 // π is inferred to be int
 let (x, y) = (10, 20.8)                             // x = 10, y = 20.8
 // x is inferred to be int and y is inferred to be double

The code above shows that multiple variables or multiple constants can be initialized simultaneously using parentheses “()”. Again, “π” is written as the name of the constant. Swift can also use emoji icons and special characters in variables or constants or other identifier names. For example,

let π = 3.14159       // any special characters
 let  hello  = " hello world "  // any unicode supported characters
 let  Steve  = " The name of a legend "  // any unicode supported characters
 let 🐶🐮 = "dogcow"     // any emoji icons
Press Control + Command + Spacebar together to get a list of emoji characters.

You can specify the datatype explicitly when declaring variables or constants. For this, after the name of the variable or constant, the data type has to be written with a colon (:) and then space. This is how to tell about a datatype separately, called type annotation.

var annotatedMessage: String = "Hello World! This variable is Type Annotated" 

Well, have we noticed that none of the above programs have a semicolon at the end of a statement? Unlike other programming languages, Swift does not require a semicolon at the end of a statement. But if you want, you can give it. There will be no error. Again, if you want to write more than one statement in a line, you must put a semicolon at the end of the statements.

println("I am the first statement. I need semicolon"); println("I am the last      statement. I don't need semicolon")
println("Another Line, I don't need any semicolon.But you can give me a semicolon if you want."); 

One of the best web sites for learning iOS app development using Swift programming is: raywenderlich

Note: More Info (Tech24InfoBD) (Swift programming language)

LEAVE A REPLY

Please enter your comment!
Please enter your name here