What is Swift

 

Swift

Swift is a new programming language for iOS, watchOS, MacOS, and tvOS apps that build on the best of C & Objective-C, without of the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to more flexible, make programming easier, and more fun. Swift’s clean slate, backed by the much-loved Cocoa and Cocoa Touch frameworks and mature, is an opportunity to reimagine how software development works.

Swift is a new programming language for iOS, watchOS, MacOS, objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming more flexible, easier, and more fun. Swift’s clean slate, Cocoa Touch frameworks, is an opportunity to reimagine how software development works. Apple laid the foundation for Swift by advancing our existing compiler, and framework infrastructure. We simplified the memory management access with Automatic Reference Counting (ARC).Swift feels familiar to Objective-C developers. It provides seamless access to mix-and-match interoperability with Objective-C code existing and Cocoa frameworks.It adopts the readability of the power of Objective-C’s dynamic object model and Objective-C’s named parameters. Building from this common ground, Swift introduces many new features and unifies the object-oriented and procedural portions of the language.

Paradigm

Multi-paradigm, protocol-oriented, Objective – Oriented, Functional, imperative, block Structured.

Designed by

Chris Lattner. And Apple Inc.

k2

First Appeared

June 2, 2014, 3 years ago.

Features

Syntactic sugar.

File Handling

Optional and Chaining

Value Types

Protocol-oriented programming

Runtime and development, Libraries,

Memory management

Debugging and  other elements

Syntactic sugar

In Swift, many of these basic types have been promoted to the language is core, and can be manipulated directly. For instance, strings are invisibly bridged to NSString and can now be concatenated with the + operator

var str = “Bitware”

str += ” Technologies”

print(str) //output: Bitware Technologies

File handling

Swift supports five HYPERLINK “https://en.wikipedia.org/wiki/Encapsulation(object-oriented_programming)” \o “Encapsulation (object-oriented programming)” access control levels for symbols: public, and private, open, internal, file private.

Optional and chaining

Optional types are created with the Optional mechanism—to make is an Integer that is nullable one would use a declaration similar to var optionalInteger: Optional<Int>

Protocol

Swift adds the ability to add these methods using extensions, and to use HYPERLINK “https://en.wikipedia.org/wiki/Generic programming” \o “Generic programming” generic programming (generics) to implement it will be using protocol.

Eg:

Protocol SupportToString

{

func toString() -> String

}

extension String: SupportToString

{

func toString() -> String

{

return self

}

}

Swift

Swift combines the best of c and Objective- C. It’s ideal for creating new apps and works seamlessly with Objective – C, so it’s compatible with apps previously created in that language.

“Bitware Technologies” Printing text is easy.

e.g print(“Bitware Technologies”)

To print the value of variable inside a text, place in parenthesis, & insert a backslash just prior to the opening parenthesis

e.g print(“The value is\(myvariable)”)

Comments

The swift compiler ignores comments, which are used to include non-executable text in your code

that may be used as a reminder or a note to self. A single line comment open with two forward-slash (//).

Eg. // this is a comment

Eg. /*this is a multiline comment*/

The tools

To build an app with swift, you will need a Mac computer(OS X 10.10 or later), running the latest version of Xcode, which features a playground, a powerful tool that allows you to run swift code with easy.

k3

k4

Constants & variables

Constants & variable are used to associate a name (your name or welcome message) with a value (the no of 42 or the string “Hi”). A constant has a set value that cannot be changed, the value of a variable can be changed. The keyword var is used to declare a variable, and key word let use to declare constant.

Eg. var a = 42//variable declaration

Eg. let a = 42//constant declaration

Type Annotations

Type annotation ensures that your code is clear about the value store about constant or variable. Swifts basic types include:

Int: Integers

Double and float: Floating point values

Bool: Boolean values

String: Textual data

Eg. var welcomemsg: String

welcomemsg = “BiteareTechonology”

Basic Operators

An operator is a special symbol to check, change or combine values. Operator are unary, binary, or ternary

Unary operator: eg. (!b)

Binary operator: eg. (a+b)

Ternary operator : eg. (a ? b : c)

Assignment Operators

The assignment operator (a=b) initialize or update the value of a with the value of b

Eg. let b = 7

var a = 42

a = b

 

 

 

 

Kondhiram Sonawane

Kondhiram is an experienced iOS developer holding experience of 1 year expertise in Objective-c | Swift 3.0

Kondhiram Sonawane

About Kondhiram Sonawane

Kondhiram is an experienced iOS developer holding experience of 1 year expertise in Objective-c | Swift 3.0