Latest Swift (IOS) Interview Question.
Q: Explain what Lazy stored properties are and when they are useful.
Price: Lazy stored properties are used for a property whose initial values are not set until the first time it is used . You can declare a lazy stored stored property by writing the lazy modifier before its declaration. Lazy properties are useful when the initial value of a property is reliant on outside factors whose values are unknown.
Q: List out what the different control statements used used in Swift.
Price: Continue, Break, Fallthrough and Return. However, while it’s important to know these control statements, what would really impress an interviewer is being able to have a dialogue around how each of you uses these controls, which you use most often, etc.
Q: What is optional chaining?
Price: Optional chaining is a process of querying and calling properties. Multiple queries can be chained together, and if any link in the chain is nil, then the entire chain fails.
Q: What collection types are available in Swift?
Price: Array, Dictionary, and Set - remember these are different from Swift data types!
Q: What are floating point numbers and what are the types of floating numbers in Swift?
Price: Floating numbers are numbers with a fractional component, like 3.25169 and -238.21. Floating point types can represent a wider range of values than integer types. There are two signed floating point numbers. Double represents a 64 bit floating number - it is used when floating point values must be very large. And Float represents a 32 bit floating number - it is used when a floating point value doesn’t exceed 64 bit precision.
Q: What is DispatchGroup?
Price: Allows for aggregate synchronization of work. We can use them to submit multiple different work items and track when they all complete, even though they might run on different queues. This behavior can be helpful when progress can’t be made until all of the specified tasks are complete.
Q: Explain the different types of notifications.
Price:- Locally: app still running in background - does not need server.
- Push: upload your certification, “gives the app a digital handshake” and allows the server to send notifications through the app
Q: What is the difference between Any and AnyObject?
Price: ANY can represent an instance of any type at all, including function types and optional types. AnyObject can represent an instance of any class type.
Q: What is encapsulation?
Price: Encapsulation is an object-oriented design principle and hides the internal states and functionality of objects. That means the objects keep their state information private.
Q: What is the difference between bounds and frame?
Price:- Frame: frame of view is the rectangle, represented as a location (X,Y) and size (width/height) corresponding to the superview it is contained within.
- Bounds: the bounds of a view of a rectangle, represented as a location (X,Y) and size (width/height) corresponding to its own coordinate system (0.0)
Q: What is the ? in Swift?
Price: The question mark is used during the declaration of property, as it tells the compiler that this property is optional. The property may hold a value or not, in the latter case it's possible to avoid runtime errors when accessing that property by using ?. This is useful in option changing and a variant of of this example is in conditional clues.
Q: What is the use of double question marks (“??”) ?
Price: To provide default value for a variable.
Q: What is auto-layout?
Price: Auto layout dynamically calculates the size and position of all the views in your view hierarchy based on constraints placed on those views.
Q: What is the difference between viewDidLoad and viewDidAppear? Which should you use to load data from a remote server to display in the view?
Price: viewDidLoad is called when the view is loaded, whether from a Xib file, storyboard or programmatically created in loafView. viewDidAppear is called every time the view is presented on the device. Which to use depends on the use case for your data. If the data is fairly static and not likely to change then it can be loaded in viewDidLoad and cached. However, if the data changes regularly then using viewDidAppear to load it is better. In both situations, the data should be loaded synchronously on a background threat to avoid blocking the UI.
Comments
Post a Comment