Skip to main content

Posts

Showing posts from March, 2020

Static variable vs Class variable in Swift

How Static properties differs to usual properties ? Used to create type properties with either let or var. These are shared between all objects of a class.  During class loading time, a single memory location allocated for the property if we declared as static. Static property belongs to a class (or struct) Type rather than Instance of class (or struct). Hence it also called  Type Properties What if we declare "static var" ? Since it's a variable, we can change it in future even after initialised. When we change the value of the static variable property, that property is now changed in all future instances. What if we declare "static let" ? static let instance : Singleton = Singleton() Since it's constant, we cannot change once initialised. Its value will remain same even if we share among all the instance or object of a class or struct. Useful to adopt singleton pattern. How class variables differ static variables ? It dif

Reference Type vs Value Type

How do we get to know reference type ?  In Swift , a class or closure or function can be Reference Type. In Objc, everything inherited from NSObject represents Reference Type. How do we get to know value type ?  In Swift, we have Structures, Enums and Tuples, along with Int, Double, String, Array, Dictionary, Set as well. In Objc, Number literals like NSInteger, C structures like CGPoint. When to use Reference type ? Comparing two objects those shares the same memory address (aka === ) When you want to create a shared and mutable state When to use Value Type ? Comparing instance data with == makes sense.  You want copies to have independent state.  The data will be used in code across multiple threads. How about memory Allocation ?  Heap memory for reference types.  Stack for Value types. Linked to similar questions : Struct vs Class String vs NSString (Source-Internet)

Swift Delhi Meetup - Chapter 23

I should thank Swift Delhi & Nykaa folks for hosting meetup on 25th Jan at Nykaa, Gurugram. Worth spending every minute with various developers from iOS community. We had 5 interesting sessions on app development standards, exploring & adopting new frameworks. Here I noted few take away points on each talks which could be useful for you. Below are talks lined up for the chapter. ------------------------------------------------------------------------------------------------ 1. Leveraging the power of silent push notifications Speaker: Yogesh Suthar, Sr. Software Engineer @Nykaa https://in.linkedin.com/in/yogesh-suthar Leveraging the power of silent push notifications for business growth, user retention and better user experience. Understanding the working of silent push flow, hacks and practical use-cases. 2. Distributing private frameworks using cocoapods Speaker: Sagar Rana, Sr. Software Engineer @Nykaa https://www.linkedin.com/in/ranasagar While working on