Category: ios

  • Closures, Extensions and Generics in Swift

    Closures Closures are self contained lines of code that can be passed around the application and similar to blocks in Objective-C. A typical closure syntax in Swift looks as shown below Closure Syntax { (parameters) -> return type in statements } Example closure in Swift var greetings = { (name:String, message:String) -> (String) in message…

  • Dependency Injection in Swift

    Dependency injection is a design pattern that lets you to pass the dependencies for the object instances instead of creating the them inside the instances. Let us see this with an example of an app that manages Expenses. In an Expense app we might have different components like ExpenseManager – Responsible of managing business logic…

  • Memory management in Swift

    Memory management in Swift is done by Automatic Reference Counting or ARC. Whenever a variables holds an instance of an object the memory count for that object increases by 1. And when variable becomes out of scope or set to nil, the memory count decreases 1. In the above example, we are creating two instances…

  • What are the different lifecycle methods in a typical UIViewController?

    Here is the list of Lifecycle methods in a ViewController are viewDidLoad – Called after the view controller’s view hierarchy has been loaded into memory. It is used for initial setup, such as creating and configuring UI elements. viewWillAppear – Called just before the view is about to be added to the view hierarchy and…

  • Explain App Life Cycle

    The app life cycle refers to the sequence of steps that app takes when an user launches an app until it terminates. Understanding the life cycle will help the developer to manage app behaviour and proper allocation and deallocation of resources. Image Credit :- Apple Not Running – Initial stage when the app is not…

  • Class and Struct in Swift

    Download the playground file from github (Classes and Struct) Class A class is a blue print for a real-word entity such Player, Person etc. and it is used for creating objects. Class can have properties to store values and methods to add behaviour. Let us see this with an example class called Rectangle which has…

  • What is the difference between Swift and Objective-C

    Objective-C Swift Syntax C style syntax with small-style message passing Modern and Concise Syntax Safety More permissive and allows runtime errors Strong focus on safety – enforcing memory safety, nullability check, type safety Performance Not faster than Swift Swift uses advanced compiler optimisation techniques. Interoperability Compatible with both C and C++ Swift needs bridging headers…

  • Optional binding and Optional Chaining

    Swift has a feature that lets users to assign optional value to a variable or a constant. Optional variable or constant can contain a value or a nil value. Let us take the following example which tries to find a given string in a array of string. Optional Binding var fruits = [“Apple”,”Orange”,”Grape”,”Mango”] let searchIndex…