During the end of last year, Apple announced that Swift is now an open source, thus benefiting app developers to use this language whilst building cross platform mobile apps. Nonetheless, before you rejoice the announcement and think of opting for this new open source, it is necessary that you’re aware about few basics of this language.

What is Swift?

1. Swift is a new programming language for iOS, OS X, watchOS, and tvOS apps.

2. Swift builds on the best of C and Objective-C, without the constraints of C compatibility.

3. Swift adopts safe programming patterns and adds modern features to make programming

4. The compiler is optimized for performance, and the language is optimized for development, without compromising on either.

Why Swift?

1. The first major feature of Swift is “safe by default”.

2. The improvements in app quality and stability over a huge developer community.

3. Swift includes things like more pervasive strong typing through generics and type inference.

4. Swift is compatible with existing Objective-C libraries.

5. There’s no problem with writing new modules in Swift that interoperate with existing Objective-C code bases.

6. Swift is the most-advanced programming language of 2015

Swift vs. Objective-C:

Swift-vs-Objective-C

1. Less Code Less Files:

a. Swift not only requires less code than Objective-C.

b. In Swift, you just need a .swift file. That’s why makes it easier to organize and maintain your project.

2. Faster than Objective-C:

a. Swift is faster than Objective-C.

b. Swift is faster than Objective-C when it comes to complex & huge sorting

Swift Features:

1. Type aliases: Define alternative name for existing data type – type alias AudioSample = UInt16

2. Tuples: Group of multiple values into single compound value: let http404Error = (404, “Not Found”) | let (statusCode, statusMessage) = http404Error

3. Optionals: This is a situation of variables where absent value can be declared as optionals using ? : var surveyAnswer: String?

4. Forced Unwrapping: Optional definitely having value and forcing to use it with the help of “!” called Forced unwrapping

5. String interpolation: Is a way to construct new value with mixing of different data types. : let message = “\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)”

6. Unicode: International standard for encoding, representing, and processing text in different writing systems.

7. Swift type inference: Don’t need to mention the datatype of variable. Data type of variable get decided with data with which it is initialised.

8. Implicit Fall through: Swift has no implicit fall through. Thus, it executes statement one at

9. Closures: They Are the self contained blocks of functionality. They are much similar with blocks in Objective-C

10. Enumerations: Defines type for a group of related values.

11. Class- User defined data type that will become a building block of code where properties and methods added around certain functionality.

12. Subscripts: Shortcuts for accessing member elements of classes, structures.

13. Extensions: Add new functionality to existing classes. It means categories in Objective – C

14. Difference in Classes and Structures

a. Inheritance – enables a class to inherit the characteristics of another class

b. Type casting at runtime

c. Free up resources

d. Reference counting allows to refer more than one to class instance

15. Class declaration: class name { }

16. Structure declaration: struct name { }

17. Value Type: Means whose get copied when assigned to variable or constant.

18. Reference type: Means who isn’t copied when assigned to variable or constant instead variable or constant refers to existing instance.

19. Identical operator: “===‘ – to check whether two variables or constants refer to same single instance.

20. Lazy stored properties: Whose initial values is not calculated until first time it is used.

21. Computed properties: Whose value is calculated and assigned/ accessed using get – set methods means using subscripts.

22. Property observers: Which observes and responds to changes in property’s value. Methods: willSet and didSet

23. Global and Local variables: Variables declared outside of context called global while declared within context called local variables.

24. Type properties: Means those declared with static in struct while class keyword in Class

25. Mutating: Modifying value types within instance method without creating new instance

26. Initialiser delegation: Can call other initialisers to perform part of instance initialisation. Means to call init within another init

27. Two types of initialiser: Designated and Convenience

a. Rule 1- Designated initialiser must call designated initialiser from immediate superclass

b. Rule 2 – Convenience initialiser must call another initialiser from same class

c. Rule 3 – Convenience initialise must ultimately call designated initialiser

28. Failable initialiser: Initialisation may fails – can be declared as init?

29. Deinitialzer: Called immediately when instance deallocated. deinit { }

30. Strong reference cycle: Two instances hold strong reference to each other and each instance keeps other alive – this creates cycle to which called Strong reference cycle

31. Strong by default – weak with optional – unowned with value –

32. Type casting – is a way to check the type of an instance – is & as operators

The above listed are some of the widely used language basics, which may help the programmers to undertake the assignments easily.

Written by –
Mahesh Asabe
Tech Lead – Mobisoft Infotech