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

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

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) }

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.

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.

11. How can we set view size in ios?

You have 3 option to set size and position for view in iOS.

  1. You can directly setting the frame of a view.
  2. Adding dynamism with Autoresizing mask.
  3. 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

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?

  1. open and public — anyone can access, within the module, and in code that imports the module
  2. internal — anyone can access, but only within the module (default)
  3. fileprivate — anyone can access, but only within the current Swift file
  4. private — only the enclosing 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).

20. difference between objective c and swift?

Objective C:

  1. which as header file and implementation file (i.e .h and .m)
  2. 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.
  3. Objective C is dynamic type.
  4. Objective C is licensed under General Public License.
  5. Uses the ARC supported only within the cocoa API
  6. No support for dynamic libraries

Swift:

  1. Swift is a general-purpose, high-level programming language which is highly concerned about safety, performance
  2. Easy to read and maintain.
  3. Swift is static type.
  4. Swift is apache licensed open source project.
  5. Support ARC for all APIs
  6. Dynamic libraries are supported

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. ❤❤❤❤.

iOS Developer in walmart