Differences - Swift vs Objective C & more
Swift vs Objective C
- Safe
- East to read
- Not complex
- Memory Management (all api in ARC)
- Open source
- Less code
- Map, filter reduce
- Codable, generic & lazy
- Veridic parameter
- Option chaining , guard
- Multiple return type
- Tuples
- Optional parameter in functions
- 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
Post a Comment