Differences - Swift vs Objective C & more

 Swift vs Objective C

  1. Safe
  2. East to read
  3. Not complex 
  4. Memory Management (all api in ARC)
  5. Open source
  6. Less code
  7. Map, filter reduce
  8. Codable, generic & lazy 
  9. Veridic parameter
  10. Option chaining , guard
  11. Multiple return type
  12. Tuples 
  13. Optional parameter in functions
  14. Closure & gcd are simple to implement




Structure vs Classes

Structures are value type, classes r reference type

Structures can’t be inherited

Structures dont have deinit()

Mutating required to modify the values in Structures

Enum cant have stored properties

Structures are saved in static memory(RAM) & classes in heap memory





Static, Class & Final

Static: obj cant access it. Can’t be inherited/override , cant apply to class

Class: same as static but can be override

Final: can’t be override/ inherited, can be applied to class & methods


Prevent Singleton{

Write:

Private init(){

}

}




Extension vs Inheritance

  • Are you adding general-purpose functionalities that should be available to every UITextField? If so, make an extension. All UITextField instances can call the new methods.
  • Are you adding functionality that should be restricted to special instances of UITextFieldthat you would identify precisely? If so, make a subclass. Only the instances of the subclass can use the new methods.
  • Inheritance can’t be applied on value types, but extension can
  • Inheritance cant be done on int, float, double, string, array, dictionaries but we can create an extension for these data type
  • We cant use stored properties in extensions
  • Cant override methods in extension, has to have unique method







Weak - Doesn’t hold the strong reference, can be nil/optional

Unowned - Same as weak but can hold nil value

Atomic - Its tread safe, low performance

Non-Atomic - not thread safe, high performance

Comments

Popular posts from this blog

SubString in Swift

PUSH Notification