Basics of the swift programming language , variable in the swift programming , constant in the swift programming , type safe language, optional in swift programming

basic of the swift programming , swift programming language, swift basic.

Basic of Swift Programming Language:-
Swift is new programming language use for the iOS, macOS ,tvOS, and watchOS before swift for these application development developer use c or c ++ .
Swift provide many fundament form c or c++ like Int for the integer , float and Double for the floating point number , string for the textual data and bool for the Boolean value. And there are also three collection type array , set and dictionary , about every collection type we read in details later.
Swift provide many thing that is same in c and objective c but along with those all swift also provide many advance feature like tuple that is used grouping the value.
Swift has many advance feature optional is one of them , optional means either “there is a value, and it equals x” or “there isn’t a value at all” optional is used ot handle the absence of the value.
Not only are optionals safer and more expressive than nil pointers in Objective-C, they’re at the heart of many of Swift’s most powerful features.
Swift is type safe language , it is very clear about their type you need not to tell about the type of the variable .
Ex var number = 11
Here we not tell what is type of number , swift compiler know itself the number is integer.

Swift use variable to store the value and identify the value , we can store integer , floating point , textual data or collection type in a variable. There are Two type of (variable or identifier) to store the value ,  Variable and constant .

Variable and constant – variable are use when we store the value that can be changed many time in program we called mutation of the variable and if any identifier has capability of mutation we called variable and store with the var keyword

How to define a variable –

var name = programming_IDEA

var favNumber = 07

var declareBool = true

var floatingValue = 10.12

Note : - swift fallow the camel case when we declare the variable and constant look at my variable name they all start with small letter and the second word start of the variable with capital letter , This is called camel case.

With store the value with the var we can muted the value like

Var favNumber = 09

Var name = logical programming.

Print(favNumber)

// 09

We declare constant when the value is not going to change any where in the program , and we use let keyword to store the value and value is called immutable value.

Ex –

let name = programming_IDEA

let favNumber = 07

let declareBool = true

let floatingValue = 10.12

by declaring value with the let keyword we cant change the value again in the program its give error.

let name = logical_IDEA

print(name)

its give the error for the conformation you can run this direct on the playground or online compiler you get error.

It is all about basic of the swift programming , i am trying to tell and its my best effort to understand the basic of the swift programming.

Comments

Popular posts from this blog

React-native pop up ,React-native Pop up hide on the touch of outside the pop up,

Simple function to Encryption on Mobile No,email id or any user information in react-native

Counter function for adding item in cart and select the item in the list