programming
beginner
10 sample questions
Ios Development MCQ Practice Test
Using Swift or Objective-C with Xcode.
Implementing gesture recognizers and UI components.
Q1. You're implementing a custom keyboard extension in iOS. You need to ensure the keyboard's height dynamically adjusts based on the device orientation (portrait or landscape). Which approach is MOST efficient and recommended for handling this dynamic height adjustment?
-
A. Using a UIScrollView to contain the keyboard's content and adjusting its frame.
-
B. Observing UIDevice.current.orientation changes and programmatically resizing the keyboard view.
-
C. Implementing a sizeThatFits(_:) method within the UIInputViewController subclass and returning the appropriate size based on orientation. ✓
-
D. Using Auto Layout constraints and relying on the system's intrinsic content size calculations.
Explanation: The `sizeThatFits(_:)` method is specifically designed for calculating the ideal size of a view based on its content. It's the most efficient and recommended approach for handling dynamic sizing within custom keyboard extensions because it leverages the system's layout mechanisms. While other options might work, they are less efficient or may lead to layout inconsistencies.
Q2. You're implementing a custom keyboard extension in iOS. You need to ensure that the keyboard's input mode (e.g., uppercase, lowercase) is properly synchronized with the main app's text field. Which method, provided by the UIInputViewController class, is MOST directly responsible for receiving notifications about changes to the main app's text document proxy?
-
A. textDocumentProxyDidChange
-
B. keyboardWillChangeFrame:
-
C. textWillChange ✓
-
D. updateViewConstraints
Explanation: UIInputViewController provides real callbacks textWillChange and textDidChange, which are invoked when the text document proxy is about to change / has changed. There is no method called textDocumentProxyDidChange.
Q3. You're building an iOS app that needs to perform a complex background task even when the app is suspended. Which of the following background modes is MOST suitable for executing a time-consuming operation that doesn't require immediate user interaction, potentially taking several hours to complete?
-
A. Background Fetch
-
B. Remote Notifications
-
C. Background Tasks (using beginBackgroundTaskWithExpirationHandler:) ✓
-
D. VoIP
Explanation: While Background Fetch is suitable for periodic updates, and Remote Notifications trigger actions based on received data, neither is ideal for long-running tasks. VoIP is specific to voice communication. `beginBackgroundTaskWithExpirationHandler:` provides extended execution time for tasks that need more than a few seconds, allowing for tasks spanning hours, though with system-imposed time limits to prevent excessive battery drain.
Q4. What is the purpose of the `windowScene` property in a SwiftUI app, and what is its return type?
-
A. It is used to get the current window scene and returns an optional `UIWindowScene`. ✓
-
B. It is used to create a new window scene and returns an optional `UIWindowScene`.
-
C. It is used to get the current window scene and returns an `UIWindowScene`.
-
D. It is used to create a new window scene and returns an `UIWindowScene`.
Explanation: The `windowScene` property in a SwiftUI app is used to access the current `UIWindowScene` associated with the app's scene. It's typically accessed within the `SceneDelegate` or a view that is part of a scene. The property returns an optional `UIWindowScene`.
Q5. What is the purpose of the 'SceneDelegate' class in a SwiftUI iOS app?
-
A. To manage the app's view hierarchy
-
B. To handle app lifecycle events ✓
-
C. To provide a centralized location for app-wide settings
-
D. To implement custom navigation between scenes
Explanation: The SceneDelegate class in a SwiftUI iOS app is responsible for managing the app's lifecycle events, such as when the app is launched, becomes active, or is terminated. It provides a centralized location for handling these events and is required by the iOS operating system.
Q6. What is the purpose of the `UIActivityViewController`'s `completionWithItemsHandler` parameter in iOS development?
-
A. To handle the user's selection of an activity ✓
-
B. To dismiss the activity view controller after a user interaction
-
C. To customize the activity items before presentation
-
D. To determine the presentation style of the activity view controller
Explanation: The `completionWithItemsHandler` parameter is a block that is executed when the user selects an activity. It allows the developer to handle the user's selection and take appropriate action.
Q7. In an iOS app, what is the purpose of the `UIViewControllerAnimatedTransitioning` protocol?
-
A. Defines animations for presenting and dismissing view controllers ✓
-
B. Specifies the layout for a table view cell
-
C. Determines the style of a `UIAlertController`
-
D. Handles gestures for a `UIGestureRecognizer`
Explanation: The `UIViewControllerAnimatedTransitioning` protocol is used to define custom animations for presenting and dismissing view controllers. This protocol has two required methods: `animationControllerForPresentedController` and `animationControllerForDismissedController`. By implementing this protocol, developers can provide a unique animation for presenting and dismissing view controllers, enhancing the user experience.
Q8. What is the purpose of the "UIPageViewController" class in iOS?
-
A. To display a collection of pages with a single item visible at a time ✓
-
B. To display a modal view controller with a custom transition animation
-
C. To display a single view controller with a custom presentation style
-
D. To display a collection of view controllers in a custom layout
Explanation: The UIPageViewController class is a subclass of UIViewController that displays a collection of pages with a single item visible at a time. It is designed to work with the UIPageViewControllerDataSource and UIPageViewControllerDelegate protocols to manage the display of the pages.
Q9. In an iOS app, what is the purpose of the "_weak" keyword when declaring a property in a delegate protocol?
-
A. To indicate a property that can be safely accessed from a background thread
-
B. To indicate a property that will be used to store a weak reference to another object ✓
-
C. To indicate a property that will be used to store a strong reference to another object
-
D. To indicate a property that will be used to store a block of code
Explanation: The "_weak" keyword is used to declare a weak reference to another object, which is useful in situations where the referenced object has a shorter lifespan than the referencing object. This is particularly useful in delegate protocols, where the delegate object may be deallocated before the referenced object.
Q10. In iOS development, what is the purpose of the `UITextFieldDelegate` protocol?
-
A. To handle user authentication
-
B. To validate and format user input ✓
-
C. To manage the keyboard's appearance and behavior
-
D. To customize the appearance of the UITextField
Explanation: The `UITextFieldDelegate` protocol is used to receive notifications about changes to the text field, such as when the user types something or when the keyboard is dismissed. One of the key responsibilities of the delegate is to validate and format the user input, for example by checking if the input is a valid email address or phone number.
That was just a sample. Sign up to unlock the full question bank with timed tests and certificates.
Sign Up Free