Top 20 iOS interview Questions — Part 2
Next top 20 1st round interview question which need to know before attending any interview.
1. What is application life cycle?
The application life cycle constitutes the sequence of events that occurs between the launch and termination of application.
- Not Running state
- Inactive state
- Active state
- Background state
- Suspended state
To know more about application life cycle refer blog here
2. What is optional?
which handles the absence of a value. Optional says either “there is a value, and it equals x” or “there isn’t a value at all”.
Optional is a super powered enum which has two values. None and Some(Wrapped), where Wrapped
is an associated value of the correct data type
3. How can we create optional?
optional
in swift is to add ?
in front of the type e.g var name: String?
4. What are the ways to unwrap optionals?
- Forced Unwrapping
- Optional Binding
- Optional chaining
- With implicitly unwrapped optionals, using
!
- Nil coalescing operator
- Unwrapping using higher order function
5. What is Optional Chaining?
Optional chaining is a process for querying and calling properties, methods on an optional that might currently be nil
To know more about optionals in swift read blog here
6. How can we iterate all enum cases?
CaseIterable
protocol helps to iterating over all enum cases and gives total amount of cases.
7. What is Associated Values?
Each enum can be paired with it’s own data is called as associated type.
e.g: enum color { case blue(rgb: Int) }
To know more about enum in swift read blog here
8. What is frame and bounds?
Frame = a view’s location and size using the parent view’s coordinate system.
Bounds = a view’s location and size using it’s own coordinate system
9. What happen if we change bounds?
When you change bounds, frame hasn’t moved in the superview. But the content of frame has changed because the origin of the bounds rectangle starts at a different part of the view.
To know more on bounds and frame read blog here
10. How can we create custom views?
You can create custom view using one of the way mentioned in below.
- Using Storyboard
- Using XIB
- Creating views programatically.
To know more on creating custom view and pros and cons read blog here
11. How can we set view size in ios?
You have 3 option to set size and position for view in iOS.
- You can directly setting the frame of a view.
- Adding dynamism with Autoresizing mask.
- Positioning a view with AutoLayout
12. What is Autoresizing mask?
An integer bit mask that determines how the receiver resizes itself when its superview’s bounds change. When a view’s bounds change, that view automatically resizes its subviews according to each subview’s autoresizing mask.
13. What is Intrinsic Content Size?
Intrinsic content size ( intrinsicContentSize ) is the property of a UIView that represents the minimum required size of the view in order to display all of its content.
14. How Autolayout represent view’s intrinsic content size?
Autolayout represents a view’s intrinsic content size using content hugging
and compression resistance
constraints.
15. What is Content hugging?
The content hugging pulls the view inward so that view fits around the content.
Setting a larger value to this priority indicates that we don’t want the view to grow larger than its content.
16. What is Compression resistance?
The compression resistance pushes the view outward so that it does not clip the content.
Setting a higher value means that we don’t want the view to shrink smaller than the intrinsic content size
To know more about autolayout please read blog here
17. What is Fitting Size?
The fitting size, on the other hand, is an output from the Auto Layout engine. Fitting size is the size calculated for a view based on the view’s constraints. e.g for this is stackview.
syntax:
systemLayoutSizeFitting(_:withHorizontalFittingPriority:verticalFittingPriority:)
18. what are Access Control in Swift?
open
andpublic
— anyone can access, within the module, and in code that imports the moduleinternal
— anyone can access, but only within the module (default)fileprivate
— anyone can access, but only within the current Swift fileprivate
— only theenclosing
declaration can access, such as a class or struct.
19. what is difference between open and public access control?
public
classes and class members can only be subclassed and overridden within the defining module (target where they’re defined).open
classes and class members can be subclassed and overridden both within and outside the defining module (target where they’re defined).
To know more about access control please read blog here
20. difference between objective c and swift?
Objective C:
- which as header file and implementation file (i.e .h and .m)
- Objective C is a general purpose language which is considered as superset of C language it was designed in an aim of providing object-oriented capabilities.
- Objective C is dynamic type.
- Objective C is licensed under General Public License.
- Uses the ARC supported only within the cocoa API
- No support for dynamic libraries
Swift:
- Swift is a general-purpose, high-level programming language which is highly concerned about safety, performance
- Easy to read and maintain.
- Swift is static type.
- Swift is apache licensed open source project.
- Support ARC for all APIs
- Dynamic libraries are supported
statically typed means that all your variables, constants, functions must have their types declared in advance
Dynamic libraries are usually shared between applications, therefore the system needs to store only one copy of the library and let different processes access
I hope you find this blog helpful. If you enjoyed it, feel free to hit the clap button below 👏 to help others find it! and follow me on Medium. Thanks for reading. ❤❤❤❤.