iOS For Beginner

Basics of Swift & Objective C

The very first thing to keep in mind is that, for creating any type of iOS app we must be strong in basic syntax of programming. In this chapter we explain the basic syntax and the main difference between two languages (objective c & swift). Let’s first see some important concepts involved in swift.

Variable & Constants:

Declaring a variable in swift is done using var Keyword

var A = 99
var B = “Hello World”

You notice that two variable A and B are of different types. A is an integer ,while B is a string. Swift is a type of safe language and it can reduce variable type from the assigned value. To make it more readable, you can write something like this :

var y:Int y = 3

Constants are also declared in similar way , but we declare them using let instead of var. The value of a constant doesn’t need to be known in compile time.

let c = 12

Optional :

Constants need to be initialized when we declare them, and variables need to be initialized before use them. Swift introduces optional value, optional value can have a value or be nil. If you take a look at the following code. In that you will notice that x was assigned an optional value “some name”. This means that swift compiler was aware that x might also be nil

In advance we have also bitwise AND,OR,NOR ,.etc operator. So these are some important thing to know in basic swift language. Now let see the difference between both languages. Even for your interview it will be very useful

SWIFT

OBJECTIVE ­ C

Swift brings type safety to iOS development and because of the static
type can optimize call and directly call the methods.

Dynamic typing is support means type of the object it points is not checked at compile time.

Swift strings are improvement over Objective C without worrying about using a mutable or immutable string type.

By using NSString objective C string is represented and it’s a subclass of NSMutableString which provide many different ways to creating objects.

File extension .swift

File extension .h,.m

swift is friendly to new programmers which support playgrounds an innovative feature which allow programmer to experiment with the code and see results immediately without run the app.

objective C is beginning of iOS and their syntax is easy to understand features that makes it user friendly which also hold much
importance and quite popular.

Some of the advantages of swift over Objective C is that memory is managed automatically, map and filter functional programming is a huge advantage, healthy debugging console in Xcode which include an interactive version of swift.