About Swift


Swift is the safe, interactive and concise language. Following are the notable things in Swift language for objective C developers.
  • Explicit pointer usage is not required in Swift unlike Objective C
  • No semicolon is needed at the end of the statement
  • Conditional expression is not necessarily included in parenthesis for if, while, do while, switch statements
  • print() is used to print messages to the console in swift
  • var and let are two important keywords in swift programming language
  • var is used to create mutable object variables and let is used to create immutable object variables in Swift
  • var should be either initialized or type defined. if you creating variables in the class context, you must initialize variables using default/custom initializers.
  • Do while not allowed in Swift instead use repeat while which is conceptually equivalent.
  • Just like Objective C, multiple inheritance is not supported by Swift, however a Swift class can conform to multiple protocols.
  •  String interpolation in Swift is a way to construct a new string value from a mix of constants, variables, literals, and expressions by including their values in a string literal. Each item you include in a string literal is wrapped in a pair of parenthesis prefixed by a backslash.
  • Swift does not support implicit conversion of values E.g var i = 4 cannot be changed to i = 4.5 during some point in the program.
  • Swift infers the data type implicitly based on the initialized values
  • functions in swift are conceptually equivalent to methods in objective C
  • Arrays are zero based and accessed using sequence of integers.
  • Arrays are strongly typed/type safe (all the elements in the array should be of same data type unless using “Any" keyword)
  • Dictionaries are strongly typed in Swift (elements in dictionary is accessed using unique key)
  • All the keys in the dictionary should be specific type and all the values in the dictionary should of specific type. All the keys and values of dictionary can be of same type but the number of types dictionary can accommodate is restricted to two unless using “Any” keyword
  •  Switch statement in swift must be exhaustive, can provide ranges of values ( closed range operator and half open range operator). No automatic implicit fall though unlike Objective C- code , but can be achieved by writing fallthrough control transfer statement.

No comments:

Post a Comment