Thursday, January 18, 2018

Mention what is the difference between Swift and ‘Objective-C’ language?

Swift Objective-C
  • In a swift, the variable and constants are declared before their use
  • You have to use “let” keyword for constant and “var” keyword for variable
  • There is no need to end code with semi-colon
  • Concatenating strings is easy in swift and allows to make a new string from a mix of constants,  literals, variables, as well as expressions
  • Swift does not require to create a separate interface like Objective C. You can define classes in a single file (.swift)
  • Swift enables you to define methods in class, structure or enumeration
  • In Swift, you use “ +=” Operator to add an item
  • In objective C, you have to declare variable as NSString and constant as int
  • In objective C, variable is declared as “ and constant as “
  • The code ends with semi-colon
  • In objective C, you have to choose between NSMutableString and NSString for string to be modified.
  • For classes, you create separate interface (.h) and implementation (.m) files for classes
  • Objective does not allow this
  • In C, you use “addObject”: method of NSMutable array to append a new item to an array