Posts

Showing posts with the label Swift

Dispatch techniques: Dynamic dispatch and Static Dispatch

4 types of dispatch techniques — Inline  (Fastest) Static Dispatch Virtual Dispatch Dynamic Dispatch  (Slowest) Dynamic dispatch Swift  allows a class to override methods and properties declared in its superclasses. ... This technique, called  dynamic dispatch , increases language expressivity at the cost of a constant amount of runtime overhead for each indirect usage. Method Dispatch is the mechanism that helps to decide which operation should be executed, or more specifically, which method implementation should be used. Dynamic Dispatch  is supported only by  reference types ( i.e.  Class). The reason for this is that, for  dynamism , or  dynamic dispatch,  in short, we need  inheritance  and our  value types  do not support inheritance. To achieve  Dynamic Dispatch , we use inheritance, subclass a base class and then override an existing method of the base class. Also, we can make use of  dynamic  k...

How would you describe a Swift language?

Image
  Swift: Language was developed by ‘ Chris Lattner ‘ with an aim to resolve difficulties existed in Objective C. It was introduced at  Apple’s 2014 Worldwide Developers Conference (WWDC)  with version  Swift 1.0 .  Swift is a type safe Multi-paradigm: protocol-oriented, object-oriented,  functional , imperative, block structured, declarative programming. Type-safe:  Swift is a  type-safe  language, which means the language helps you to be clear about the types of values your code can work with. If part of your code requires a  String , type safety prevents you from passing it an  Int  by mistake. Likewise, type safety prevents you from accidentally passing an optional  String  to a piece of code that requires a non-optional  String . Object-oriented: Object - Oriented  Programming (  OOP  ) helps you structure your  Swift  code with so-called classes. These classes have properties and fun...

MVVM and MVC in swift

MVC:  View  is supposed to be inactive and only displays prepared data on demand. Model : It represents simple data. Controller   should work on the   Model   data to prepare it for the   Views , which then display that data. View  is also responsible for notifying the  Controller  about any actions, such as user touches. UIViewController  is supposed to be a  Controller  in the MVC pattern,  MVVM:  The Model View ViewModel (MVVM) is an architectural pattern used in software engineering. Models  hold application data / Content. They’re usually structs or simple classes.  Views  display visual elements and controls on the screen. They’re typically  UIView and UIViewController . xib and storyboards View models  transform model information into values that can be displayed on a view. They’re usually classes, so they can be passed around as references. ViewModel  hides all asynchronous networ...

iOS Questions (Persistence & Databases)

  Core Data   Core Data is a framework used to save, track, modify and filter the data within iOS apps, however, Core Data is not a Database. It allows  data  organised by the relational entity–attribute model to be serialised into XML, binary, or SQLite stores. Core Data is using SQLite as its persistent store but the framework itself is not the database. Core Data is an ORM (Object Relational Model) which creates a layer between the database and the UI. It speeds-up the process of interaction as we don’t have to write queries, just work with the ORM and let ORM handles the backend. Core Data stack - Manage and persist your app’s model layer. A stack contains all the Core Data components you need to fetch, create, and manipulate managed objects. Core Data provides a set of classes that collaboratively support your app’s model layer: (through fetch , create, manipulate manage objects) A Core Data stack is composed of the following objects:  1. NSManagedObjectCon...

iOS Questions (Swift Programming Language)

Image
  1. What’s the difference between  var  and  let ?  Both var and let are references, therefore let is a const reference. let is used to declare a constant value - you won't change it after giving it an initial value. Its a immutable variable. let theAnswer = 42 The theAnswer cannot be changed afterwards. This is why anything weak can't be written using let. They need to change during runtime and you must be using var instead. The var defines an ordinary variable. What is interesting: The value of a constant doesn’t need to be known at compile time, but you must assign the value exactly once. Another strange feature: You can use almost any character you like for constant and variable names, including Unicode characters: let 🐶🐮 = "dogcow" let defines a "constant". Its value is set once and only once, though not necessarily when you declare it. For example, you use let to define a property in a class that must be set during initialization: var is used to dec...

Certificate pinning and Alamofire

1.  Alamofire and URLSession.  both help you to make network requests in Swift.   Main advantage for Alamofire: Certificate pinning . It can take some time to sort this out and build this yourself. Asymmetric cryptography :  The second phase uses  public-key cryptography  or  asymmetric cryptography . This is a cryptographic system that uses pairs of keys: Public keys, which are widely disseminated and private keys, which only the owner knows. The third phase uses  symmetric-key cryptography , where you use the same key for both encryption of plaintext and decryption of ciphertext. In other words, you configure the app to reject all but one or a few predefined certificates or public keys. Whenever the app connects to a server, it compares the server certificate with the pinned certificate(s) or public key(s). If and only if they match, the app trusts the server and establishes the connection. You usually add a service’s certificate or public key a...