Swift Interview Questions & Answers

Theory-Based Questions

Dive into our extensive collection of 51 theory-based JavaScript interview questions.

Console-Based I/O Questions

Enhance your problem-solving skills with our 44 console-based input/output questions.

JavaScript Programs

Explore our curated selection of JavaScript programs designed to test your coding abilities.

List 1
List 2
List 3

Question 1:- What is the purpose of the @State property wrapper in SwiftUI?

Answer: @State is used for local state management. It allows views to update dynamically when the state changes.

Question 2:- What is the difference between @State and @Binding in SwiftUI?

Answer: @State is for local state, while @Binding allows a child view to modify state owned by its parent.

Question 3:- Explain the use of the @ObservedObject property wrapper.

Answer: @ObservedObject allows a view to observe an external object conforming to the ObservableObject protocol.

Question 4:- What does the NavigationView component do in SwiftUI?

Answer: NavigationView provides a container that enables navigation between views using NavigationLink.

Question 5:- What is a VStack in SwiftUI?

Answer: VStack arranges its child views vertically in a stack.

Question 6:- What is a ZStack in SwiftUI?

Answer: ZStack overlays its child views on top of each other.

Question 7:- How does the .onAppear() modifier work in SwiftUI?

Answer: The .onAppear() modifier executes a closure when the view appears on the screen.

Question 8:- What is the difference between .frame() and .padding() in SwiftUI?

Answer: - .frame() specifies the size of a view.
        - .padding() adds space around the view's content.

Question 9:- What are the benefits of declarative syntax in SwiftUI?

Answer: Declarative syntax simplifies UI code, reduces bugs, and improves readability.

Question 10:- What does the ForEach loop do in SwiftUI?

Answer: ForEach iterates over a collection and creates views for each element.

Question 11:- What is the purpose of GeometryReader?

Answer: GeometryReader provides access to the size and position of a view's container, enabling dynamic layouts.

Question 12:- What are ViewModifiers in SwiftUI?

Answer: ViewModifiers allow you to encapsulate reusable configurations for views, such as custom padding or backgrounds.

Question 13:- How does .animation() work in SwiftUI?

Answer: .animation() adds implicit animations to view property changes.

Question 14:- What is @EnvironmentObject, and how is it different from @ObservedObject?

Answer: @EnvironmentObject allows sharing data across multiple views without explicit passing, while @ObservedObject requires direct injection.

Question 15:- What does the .clipShape() modifier do in SwiftUI?

Answer: The .clipShape() modifier clips a view to a specified shape, such as Circle or RoundedRectangle.

Question 16:- How does SwiftUI manage data flow?

Answer: SwiftUI uses property wrappers like @State, @Binding, and @EnvironmentObject to manage data flow.

Question 17:- What is the difference between .sheet() and .popover() in SwiftUI?

Answer: .sheet() displays a modal view, while .popover() shows a popover anchored to a specific view.

Question 18:- What are App storage and Scene storage in SwiftUI?

Answer: AppStorage persists data using UserDefaults, while SceneStorage is used for temporary state restoration.

Question 19:- What is the purpose of @Published in SwiftUI?

Answer: @Published notifies observers when a property changes, often used in ObservableObject.

Question 20:- How does Combine integrate with SwiftUI?

Answer: Combine powers SwiftUI's reactive data flow, enabling asynchronous programming with Observables.
List 1
List 2
List 3

Contact Us

This website uses cookies to enhance the user experience. We use first-party cookies to track user sessions and preferences.