Unit 5: iPhone Project Templates - Practice Quiz
1
What is the main purpose of a UINavigationController in an iPhone application?
2 Which operation displays a new view controller on a navigation stack?
3 What usually happens when the Back button is tapped in a navigation controller?
4 What does Auto Layout use to determine the position and size of interface elements?
5 What is a major benefit of using Auto Layout?
6 Which constraint controls the horizontal distance between two views?
7 Which class is commonly used to play a local audio file in an iOS application?
UICollectionView
UITabBarController
AVAudioPlayer
UINavigationItem
8 Which framework provides common classes for audio and video playback in iOS?
CoreLocation
Contacts
AVFoundation
MapKit
9 Which class can be used to play both local and streamed media?
UISlider
AVPlayer
UITableViewCell
UILabel
10
What is the primary use of a UICollectionView?
11 What is an individual item in a collection view usually represented by?
UITabBarItem
AVPlayerItem
UICollectionViewCell
UINavigationBar
12 Which object provides the data displayed by a collection view?
13
What is the main purpose of a UIToolbar?
14
Which objects are commonly placed inside a UIToolbar?
UINavigationController objects
UIBarButtonItem objects
UICollectionViewCell objects
AVAudioPlayer objects
15 What is the purpose of a tab bar in an iPhone application?
16 Which controller is commonly used to manage a tab-based interface?
UITabBarController
UIAlertController
UISplitViewController
UIImagePickerController
17 What happens when a user selects a different tab bar item?
18 What type of database is SQLite?
19 Which SQL command is used to retrieve records from an SQLite table?
SELECT
INSERT
DELETE
UPDATE
20 Which SQL command adds a new record to an SQLite table?
SELECT
UPDATE
INSERT
DROP
21 A view controller must open a detail screen and display a Back button automatically. Which approach should be used?
pushViewController(_:animated:)
present(_:animated:)
22 An application has pushed three view controllers: Home, Products, and Details. Which call returns directly from Details to Home?
setViewControllers([], animated:)
popToRootViewController(animated:)
dismiss(animated:completion:)
popViewController(animated:)
23
A navigation controller should begin with HomeViewController as its first screen. Which initialization is appropriate?
UINavigationController(nibName: "Home", bundle: nil)
UINavigationController(coder: homeController)
UINavigationController(navigationBarClass: nil, toolbarClass: nil)
UINavigationController(rootViewController: homeController)
24 A button must remain 20 points from the trailing edge of its container in both portrait and landscape orientations. Which constraint best achieves this?
button.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20)
button.widthAnchor.constraint(equalToConstant: 20)
button.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
button.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 20)
25 A label with variable text should expand horizontally before a nearby button is compressed. Which Auto Layout setting should be adjusted?
26 A programmatically created view ignores its anchor constraints and keeps an autoresizing-mask-based frame. What change is required?
clipsToBounds to true
autoresizesSubviews to false
translatesAutoresizingMaskIntoConstraints to false
isUserInteractionEnabled to true
27 An application needs to play a short local audio file and provide direct controls for play, pause, and volume. Which class is most appropriate?
AVPlayerViewController
AVAudioPlayer
AVCaptureSession
MPMediaPickerController
28
A developer creates an AVAudioPlayer for a local file, but no sound is produced because playback was never initialized. Which sequence should be used?
startRunning() and then play()
seek(to:) and then present()
prepareToPlay() and then play()
loadView() and then resume()
29 An application must stream a remote video and display standard playback controls. Which combination is appropriate?
MPMediaPickerController with WKWebView
AVAudioPlayer with UIImageView
AVPlayer with AVPlayerViewController
AVCaptureDevice with UIToolbar
30 A collection view cell appears with old content while scrolling because cells are reused. Where should the cell's labels and images normally be assigned?
collectionView(_:didSelectItemAt:)
collectionView(_:layout:sizeForItemAt:)
collectionView(_:numberOfItemsInSection:)
collectionView(_:cellForItemAt:)
31 After inserting an item into a collection view's data source, which update correctly keeps the interface synchronized?
reloadSections([])
insertItems(at:)
setNeedsLayout(), then delete the old model item
reloadInputViews(), then insert the model item
32
A collection view uses UICollectionViewFlowLayout. Which delegate method can provide a different size for each item?
collectionView(_:didHighlightItemAt:)
collectionView(_:shouldSelectItemAt:)
collectionView(_:willDisplay:forItemAt:)
collectionView(_:layout:sizeForItemAt:)
33 A toolbar needs Save aligned left and Delete aligned right. Which item should be placed between the two buttons?
34
A UIToolbar has been created programmatically with three bar button items. Which property should receive those items?
toolbar.subviews
toolbar.items
toolbar.constraints
toolbar.gestureRecognizers
35 An application has Home, Search, and Settings sections, each requiring its own navigation history. What hierarchy is most appropriate?
36
A developer wants the Settings tab to be selected when the application first displays its three tabs. Which property should be set to 2?
selectedIndex
selectedItem
currentPage
selectionStyle
37 Which configuration adds a visible title and system icon to a view controller displayed by a tab bar controller?
UITabBarItem to tabBarItem
UIBarButtonItem to navigationItem
UIToolbar to inputView
UINavigationBar to view
38 A query must find a user by an email address supplied through a text field. Which approach best reduces the risk of SQL injection?
39 Several related SQLite updates must either all succeed or all be undone. Which SQL commands should surround the updates?
ATTACH DATABASE and DETACH DATABASE
BEGIN TRANSACTION and COMMIT
SELECT and ORDER BY
CREATE TABLE and DROP TABLE
40
An SQLite query has been prepared with sqlite3_prepare_v2. Which return value from sqlite3_step indicates that a row of result data is available?
SQLITE_BUSY
SQLITE_ROW
SQLITE_DONE
SQLITE_OK
41
A view controller pushed onto a UINavigationController needs to animate a custom subview alongside both interactive and noninteractive pop transitions. Which approach correctly keeps the animation synchronized and handles cancellation?
UINavigationController.didShow notifications and compare the navigation stack afterward
transitionCoordinator and inspect the completion context
viewWillDisappear(_:) and reverse it in viewDidAppear(_:)
navigationController(_:willShow:animated:) and use a fixed-duration property animator
42
After assigning a custom object as a navigation controller's interactivePopGestureRecognizer.delegate, the edge-swipe gesture intermittently stops working. What is the most robust correction?
nil after the root controller appears
popViewController(animated:) after the user's finger crosses half the screen, while disabling the original recognizer
viewDidAppear(_:) executes
43
A navigation controller is restoring a deep stack [A, B, C] without animation. The current stack is [A, X]. Which operation replaces the entire stack atomically while preserving normal containment callbacks?
B, present C, and dismiss X after the final presentation completes
popToRootViewController(animated: false) followed by two pushes
[A, B, C] directly to the navigation controller's children property
setViewControllers([A, B, C], animated: false)
44 A horizontal stack contains a label and a text field. Both have enough constraints to determine their positions. When space becomes limited, the label must remain at intrinsic width and the text field should shrink first. Which priority change directly expresses this rule?
45
A scroll view fills its parent. Its content view is constrained on all four edges to contentLayoutGuide and has equal width to frameLayoutGuide. The content view has no explicit height, but its vertically arranged subviews form an unbroken top-to-bottom constraint chain. What behavior results?
contentSize is assigned manually after Auto Layout finishes
46
A view's horizontal position and width are fully determined, but its vertical constraints specify only a fixed height and centerY. Interface Builder still reports an ambiguous layout at runtime. Which statement is correct?
47 A spoken-audio app should pause when an interruption begins and resume only if playback was active beforehand and the interruption options indicate that resumption is appropriate. Which design is correct?
.began, and conditionally resume on .ended with .shouldResume
.began and recreate the AVPlayer whenever .ended arrives
.began and always call play() on .ended, regardless of the prior state
AVPlayer automatically restores the user's exact playback intent
48
An app loops a local video by observing AVPlayerItem.didPlayToEndTimeNotification. It later replaces player.currentItem, but looping stops. What is the most likely cause?
AVPlayerLayer before end notifications can be posted
actionAtItemEnd automatically changed to .pause during item replacement
AVPlayer instance, so a second player is required
49 A music app must continue playing when the screen locks and should mix with audio from another app at a reduced relative volume. Which audio-session configuration best matches the requirement?
.record with .defaultToSpeaker, plus the Audio background mode
.soloAmbient with .mixWithOthers, plus the Location background mode
.playback with .mixWithOthers, plus the Audio background mode
.ambient with .duckOthers, without enabling a background mode
50
A collection view currently displays 5 items. Inside performBatchUpdates, the code deletes item 1 and inserts a new item at index 4. What must the data source report when UIKit validates the completed update?
51 A diffable data source snapshot contains two visually identical messages with the same database identifier. Applying it raises an exception. What is the correct model-level fix?
52 A self-sizing collection-view cell uses Auto Layout, but its height stays at the estimated value even though multiline text needs more space. Which condition is essential inside the cell?
sizeToFit() on every visible cell after each layout pass
draw(_:) and update its frame from the text's bounding rectangle
53 A toolbar contains flexible space between two leading actions and one trailing action. When the toolbar width changes, which item absorbs the extra horizontal space?
UIBarButtonItem created with the .fixedSpace system item
UIBarButtonItem created with the .flexibleSpace system item
54 A screen is inside a navigation controller whose built-in toolbar is used. The toolbar must show items specific to the visible child controller and update correctly during pushes and pops. Where should those items be configured?
setToolbarItems(_:animated:)
UIToolbar added over the navigation controller's built-in toolbar so each child can manage its own independent bar
navigationController?.toolbar?.items from the application delegate
addSubview(_:)
55
A UITabBarController has five child controllers. The user selects the fifth tab, which appears under the system-generated More interface. Which value should application logic use to identify the selected child reliably?
selectedViewController, compared with the controller's stable application identity
selectedIndex, assumed to equal the visible position within the More table
56 Each tab contains its own navigation controller. After switching tabs, the app unexpectedly resets the previously selected tab to its root screen. Which architecture preserves independent navigation history?
didSelect is called
viewControllers
viewWillDisappear(_:) to synchronize tab state
57 The current tab should remain selected when a user taps its tab bar item again, but the tab's navigation stack should pop to root. Which delegate decision is best suited to initiate this behavior?
tabBarController(_:shouldSelect:), pop the current stack, and return false
selectedIndex to zero in viewDidDisappear(_:) of the current navigation controller
viewControllers array
tabBarController(_:didSelect:) after creating a replacement tab controller
58 An SQLite table stores bank balances. A transfer performs one debit and one credit. The process must never commit only one of them, including when the credit violates a constraint. Which sequence provides the required atomicity?
59
A prepared SQLite query uses WHERE nickname = ?. The application binds SQL NULL because the user has no nickname, but rows whose nickname is NULL are not returned. Why?
NULL are unknown; the query must use IS NULL for that case
NULL to an empty string before evaluating equality
VACUUM so null entries become visible to indexed comparisons
NOT NULL
60
Multiple background tasks share one SQLite connection opened with serialized threading support. Statements are protected by a serial queue, but a result row's text pointer is stored and read after sqlite3_step is called again. What is the defect?
sqlite3_step automatically converts text storage to UTF-16 and invalidates only numeric columns
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →