Sample questions
Question 1Easy
On which thread must UIKit and SwiftUI UI updates be made?
- The main thread
- Whichever thread the network call used
- Any background thread
- A dedicated render thread
Answer: A. The main thread
Explanation
UI frameworks are not thread-safe and expect all UI work on the main thread (the main actor).
Step-by-step solution
- UIKit and SwiftUI require updates on the main thread.
- Main thread handles all user interface operations safely.
- Network calls can run on background threads.
- UI changes must be made on the main thread only.
- Final answer: A (The main thread).
Why the other options are wrong
- B. The network thread is not safe for UI; UI work must run on the main thread.
- C. Any background thread is unsafe for UI changes; use the main thread.
- D. A render thread is internal to the system; app code uses the main thread.
Tip: Always perform UI updates on the main thread for safety.
Question 2Easy
Which values can SwiftUI's scenePhase environment value take?
- launching, running and terminated
- visible, hidden and destroyed
- active, inactive and background
- foreground and suspended only
Answer: C. active, inactive and background
Explanation
ScenePhase is .active (in front and interactive), .inactive (visible but not receiving events) or .background (not visible).
Step-by-step solution
- ScenePhase reports the state of a scene.
- Its three values are active, inactive and background.
- Marked answer: option C.
Why the other options are wrong
- A. Launching, running and terminated are not scenePhase values.
- B. Visible, hidden and destroyed are not scenePhase values.
- D. Suspended is not a scenePhase value; background is.
Tip: ScenePhase has three values: active, inactive and background.
Question 3Easy
What is the Info.plist file used for in an iOS app?
- Recording crash logs from users' devices
- Storing the user's data and documents between launches
- App settings like bundle id and permission texts
- Holding the compiled Swift code
Answer: C. App settings like bundle id and permission texts
Explanation
Info.plist is a property list read by the system to configure the app, including usage descriptions shown in permission prompts.
Step-by-step solution
- Info.plist stores app settings like bundle id and permissions.
- It provides details for the app's configuration and metadata.
- The file includes texts shown when requesting user permissions.
- It does not hold compiled code or crash logs.
- User data is stored elsewhere, not in Info.plist.
- Final answer: App settings like bundle id and permission texts.
Why the other options are wrong
- A. Crash logs come from the system or crash reporting tools, not from Info.plist.
- B. User data and documents live in the app's sandbox, not in Info.plist.
- D. Compiled code lives in the app binary, not in Info.plist.
Tip: Remember Info.plist contains app metadata, not user data or code.
Question 4Easy
In a SwiftUI app, what does the @main struct conforming to App provide?
- A list of the app's background tasks
- The app's icon and launch screen images
- The root view controller loaded from a storyboard
- The entry point, with scenes like WindowGroup
Answer: D. The entry point, with scenes like WindowGroup
Explanation
@main marks the entry point. Its body returns scenes, usually a WindowGroup with the root view.
Step-by-step solution
- @main marks the entry point of the SwiftUI app.
- The struct's body defines scenes like WindowGroup.
- These scenes determine how the app appears on screen.
- It does not handle background tasks or storyboard views.
- Thus, it provides the entry point with scenes like WindowGroup.
Why the other options are wrong
- A. Background tasks are not listed by the App struct; they are handled by system APIs.
- B. Icons and launch screen images live in asset catalogs, not in the App struct.
- C. A storyboard root view controller belongs to UIKit apps, not to SwiftUI.
Tip: @main is essential for launching SwiftUI apps and setting up the main interface.
Question 5Medium
In a UIKit view controller, how often is viewDidLoad() called compared with viewWillAppear(_:)?
- Both are called exactly once in the controller's life
- viewDidLoad once; viewWillAppear on each appearance
- viewWillAppear is called once; viewDidLoad every time
- Both are called every time the view appears
Answer: B. viewDidLoad once; viewWillAppear on each appearance
Explanation
viewDidLoad runs once after the view is loaded into memory. viewWillAppear runs before each appearance, for example when returning from a pushed screen.
Step-by-step solution
- viewDidLoad runs once, when the view loads.
- viewWillAppear runs every time the view is about to appear.
Why the other options are wrong
- A. viewWillAppear repeats.
- C. Reversed.
- D. viewDidLoad is not repeated.
Tip: Load once, appear many.
Question 6Medium
A SwiftUI app needs an AppDelegate for push notification callbacks. How is it connected?
- SwiftUI apps can't receive any AppDelegate callbacks
- By subclassing App from UIApplicationDelegate
- Via @UIApplicationDelegateAdaptor in the App struct
- By setting it in the Info.plist only
Answer: C. Via @UIApplicationDelegateAdaptor in the App struct
Explanation
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate makes SwiftUI create the delegate and forward UIKit lifecycle callbacks to it.
Step-by-step solution
- SwiftUI apps use @UIApplicationDelegateAdaptor to connect delegates.
- @UIApplicationDelegateAdaptor is added to the App struct.
- AppDelegate is specified as the delegate type with AppDelegate.self.
- This forwards UIKit callbacks to the SwiftUI app's delegate.
- The correct setup uses @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate.
Why the other options are wrong
- A. SwiftUI apps can receive those callbacks through the adaptor, so this is false.
- B. App is a protocol, not a class to subclass; the adaptor is the link.
- D. Info.plist does not connect delegate classes; the link is written in Swift.
Tip: @UIApplicationDelegateAdaptor is essential for connecting delegates in SwiftUI apps.
Question 7Medium
In a UIKit app, which AppDelegate method is the usual place for one-time setup at launch?
viewDidLoad()application(_:didFinishLaunchingWithOptions:)sceneDidEnterBackground(_:)application(_:configurationForConnecting:options:)
Answer: B. application(_:didFinishLaunchingWithOptions:)
Explanation
didFinishLaunchingWithOptions runs once after launch and before the UI is shown, so it suits setting up services such as analytics or push notifications.
Step-by-step solution
- application(_:didFinishLaunchingWithOptions:) runs once when the app starts.
- It is called after the app launches and before the UI appears.
- This makes it ideal for one-time setup tasks like initializing services.
- Other methods are used for different lifecycle events like backgrounding or connecting to devices.
- So, the correct place for one-time setup is application(_:didFinishLaunchingWithOptions:).
Why the other options are wrong
- A. viewDidLoad belongs to a view controller and runs per screen, not once at app launch.
- C. sceneDidEnterBackground runs when the scene goes to the background, not at launch.
- D. configurationForConnecting picks a scene configuration for new scenes, not launch setup.
Tip: Use didFinishLaunchingWithOptions for one-time setup in UIKit apps.
Question 8Medium
Why should an app save unsaved user data when it moves to the background?
- Background apps lose access to their own files
- The system may end a suspended app without notice
- The app is relaunched from scratch every time it is opened
- iOS deletes the app's memory when the screen locks
Answer: B. The system may end a suspended app without notice
Explanation
After a short time in the background apps are suspended, and the system may then end them to free memory without running more code. Saving on the move to background avoids data loss.
Step-by-step solution
- When the app leaves the foreground it goes to the background and can be suspended.
- The system can end a suspended app at any time to free memory, and it gives no notice.
- So unsaved data should be saved when the app moves to the background. Marked answer: option B.
Why the other options are wrong
- A. Background apps keep access to their own files.
- C. An app is not always relaunched from scratch when it is opened again.
- D. Memory is not wiped when the screen locks; the system may end a suspended app instead.
Tip: Save work when the app goes to the background; suspended apps can be ended without notice.
Question 9Hard
When a UIKit view controller is first shown, in what order are these called?
- viewDidAppear, viewWillAppear, viewDidLoad
- viewDidLoad, viewDidAppear, viewWillAppear
- viewDidLoad, viewWillAppear, viewDidAppear
- viewWillAppear, viewDidLoad, viewDidAppear
Answer: C. viewDidLoad, viewWillAppear, viewDidAppear
Explanation
The view is loaded first (viewDidLoad), then the controller is told it is about to appear and finally that it has appeared.
Step-by-step solution
- ViewDidLoad is called first to load the view.
- ViewWillAppear is called next before the view appears.
- ViewDidAppear is called last after the view has appeared.
- So order is viewDidLoad, viewWillAppear, viewDidAppear.
- Final answer: viewDidLoad, viewWillAppear, viewDidAppear.
Why the other options are wrong
- A. viewDidAppear comes last, not first; viewDidLoad runs before the view is shown.
- B. viewDidAppear fires after viewWillAppear, so placing it second is out of order.
- D. viewWillAppear cannot come first; viewDidLoad loads the view before it.
Tip: Remember the order: load, appear, did appear.
Question 10Hard
When is an app typically in the inactive state?
- Briefly, during interruptions such as an incoming call
- Whenever it is fully hidden behind other apps
- After it has been terminated by the system
- Only during the very first launch after it is installed
Answer: A. Briefly, during interruptions such as an incoming call
Explanation
Inactive means in the foreground but not receiving events, for example while Control Centre is pulled down or during the switch to background.
Step-by-step solution
- Inactive is a short transition state for an app that is running.
- It happens during interruptions such as an incoming call.
- Marked answer: option A.
Why the other options are wrong
- B. A fully hidden app is in the background, not inactive.
- C. A terminated app is not running, so it is not inactive.
- D. Inactive is not tied to the first launch.
Tip: Inactive is brief and happens during interruptions; background is for hidden apps.
Practise all 12 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →