Unit 5: iPhone Project Templates - Practice Quiz

INT372 — Iphone Application Programming 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the main purpose of a UINavigationController in an iPhone application?

Using navigation controllers Easy
A. To arrange views with constraints
B. To manage a stack of view controllers
C. To store data in a local database
D. To play audio files in the background

2 Which operation displays a new view controller on a navigation stack?

Using navigation controllers Easy
A. Reloading the view controller
B. Pushing the view controller
C. Deleting the view controller
D. Pausing the view controller

3 What usually happens when the Back button is tapped in a navigation controller?

Using navigation controllers Easy
A. The top view controller is popped
B. The navigation bar is hidden
C. The application data is cleared
D. The root view controller is deleted

4 What does Auto Layout use to determine the position and size of interface elements?

Concept of auto-layout Easy
A. Navigation stacks
B. Database records
C. Audio channels
D. Layout constraints

5 What is a major benefit of using Auto Layout?

Concept of auto-layout Easy
A. It converts videos into audio files
B. It adapts interfaces to different screen sizes
C. It creates navigation controllers automatically
D. It stores application data in tables

6 Which constraint controls the horizontal distance between two views?

Concept of auto-layout Easy
A. A height constraint
B. A horizontal spacing constraint
C. An aspect ratio constraint
D. A vertical spacing constraint

7 Which class is commonly used to play a local audio file in an iOS application?

Playing audio and video files Easy
A. UICollectionView
B. AVAudioPlayer
C. UINavigationItem
D. UITabBarController

8 Which framework provides common classes for audio and video playback in iOS?

Playing audio and video files Easy
A. MapKit
B. Contacts
C. AVFoundation
D. CoreLocation

9 Which class can be used to play both local and streamed media?

Playing audio and video files Easy
A. AVPlayer
B. UILabel
C. UISlider
D. UITableViewCell

10 What is the primary use of a UICollectionView?

Implementing UICollectionView Easy
A. Displaying items in customizable layouts
B. Managing a stack of screens
C. Executing commands in a database
D. Playing a sequence of audio files

11 What is an individual item in a collection view usually represented by?

Implementing UICollectionView Easy
A. UITabBarItem
B. UINavigationBar
C. UICollectionViewCell
D. AVPlayerItem

12 Which object provides the data displayed by a collection view?

Implementing UICollectionView Easy
A. The layout guide
B. The data source
C. The navigation item
D. The audio session

13 What is the main purpose of a UIToolbar?

Implementing UIToolbar Easy
A. To display records in database tables
B. To arrange cells in a grid
C. To manage multiple navigation stacks
D. To display a row of action buttons

14 Which objects are commonly placed inside a UIToolbar?

Implementing UIToolbar Easy
A. UINavigationController objects
B. AVAudioPlayer objects
C. UIBarButtonItem objects
D. UICollectionViewCell objects

15 What is the purpose of a tab bar in an iPhone application?

UITabBar in applications Easy
A. To execute queries on local records
B. To switch between major application sections
C. To define relationships between view sizes
D. To control the volume of audio

16 Which controller is commonly used to manage a tab-based interface?

UITabBar in applications Easy
A. UITabBarController
B. UIImagePickerController
C. UIAlertController
D. UISplitViewController

17 What happens when a user selects a different tab bar item?

UITabBar in applications Easy
A. The associated view controller is displayed
B. The current database table is removed
C. The application audio is automatically paused
D. All Auto Layout constraints are disabled

18 What type of database is SQLite?

Database using SQLite Easy
A. A remote document database
B. A cloud-only graph database
C. An embedded relational database
D. An in-memory key-value cache

19 Which SQL command is used to retrieve records from an SQLite table?

Database using SQLite Easy
A. UPDATE
B. INSERT
C. SELECT
D. DELETE

20 Which SQL command adds a new record to an SQLite table?

Database using SQLite Easy
A. UPDATE
B. DROP
C. INSERT
D. SELECT

21 A view controller must open a detail screen and display a Back button automatically. Which approach should be used?

Using navigation controllers Medium
A. Add the detail controller as a child controller
B. Push the detail controller with pushViewController(_:animated:)
C. Replace the navigation controller's root controller
D. Present the detail controller with present(_:animated:)

22 An application has pushed three view controllers: Home, Products, and Details. Which call returns directly from Details to Home?

Using navigation controllers Medium
A. popViewController(animated:)
B. setViewControllers([], animated:)
C. popToRootViewController(animated:)
D. dismiss(animated:completion:)

23 A navigation controller should begin with HomeViewController as its first screen. Which initialization is appropriate?

Using navigation controllers Medium
A. UINavigationController(rootViewController: homeController)
B. UINavigationController(navigationBarClass: nil, toolbarClass: nil)
C. UINavigationController(coder: homeController)
D. UINavigationController(nibName: "Home", bundle: nil)

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?

Concept of auto-layout Medium
A. button.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
B. button.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20)
C. button.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 20)
D. button.widthAnchor.constraint(equalToConstant: 20)

25 A label with variable text should expand horizontally before a nearby button is compressed. Which Auto Layout setting should be adjusted?

Concept of auto-layout Medium
A. Give the label a higher compression-resistance priority
B. Give the button a lower content-hugging priority
C. Give the button a higher compression-resistance priority
D. Give the label a lower content-hugging priority

26 A programmatically created view ignores its anchor constraints and keeps an autoresizing-mask-based frame. What change is required?

Concept of auto-layout Medium
A. Set isUserInteractionEnabled to true
B. Set translatesAutoresizingMaskIntoConstraints to false
C. Set clipsToBounds to true
D. Set autoresizesSubviews to false

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?

Playing audio and video files Medium
A. MPMediaPickerController
B. AVAudioPlayer
C. AVCaptureSession
D. AVPlayerViewController

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?

Playing audio and video files Medium
A. Call seek(to:) and then present()
B. Call loadView() and then resume()
C. Call prepareToPlay() and then play()
D. Call startRunning() and then play()

29 An application must stream a remote video and display standard playback controls. Which combination is appropriate?

Playing audio and video files Medium
A. AVCaptureDevice with UIToolbar
B. MPMediaPickerController with WKWebView
C. AVPlayer with AVPlayerViewController
D. AVAudioPlayer with UIImageView

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?

Implementing UICollectionView Medium
A. Inside collectionView(_:didSelectItemAt:)
B. Inside collectionView(_:layout:sizeForItemAt:)
C. Inside collectionView(_:cellForItemAt:)
D. Inside collectionView(_:numberOfItemsInSection:)

31 After inserting an item into a collection view's data source, which update correctly keeps the interface synchronized?

Implementing UICollectionView Medium
A. Insert the model item, then call reloadSections([])
B. Call reloadInputViews(), then insert the model item
C. Call setNeedsLayout(), then delete the old model item
D. Insert the model item, then call insertItems(at:)

32 A collection view uses UICollectionViewFlowLayout. Which delegate method can provide a different size for each item?

Implementing UICollectionView Medium
A. collectionView(_:willDisplay:forItemAt:)
B. collectionView(_:layout:sizeForItemAt:)
C. collectionView(_:shouldSelectItemAt:)
D. collectionView(_:didHighlightItemAt:)

33 A toolbar needs Save aligned left and Delete aligned right. Which item should be placed between the two buttons?

Implementing UIToolbar Medium
A. A system Done bar button item
B. A flexible-space bar button item
C. A custom plain bar button item
D. A fixed-space bar button item

34 A UIToolbar has been created programmatically with three bar button items. Which property should receive those items?

Implementing UIToolbar Medium
A. toolbar.items
B. toolbar.gestureRecognizers
C. toolbar.subviews
D. toolbar.constraints

35 An application has Home, Search, and Settings sections, each requiring its own navigation history. What hierarchy is most appropriate?

UITabBar in applications Medium
A. A toolbar containing three navigation controllers
B. A tab bar controller containing three navigation controllers
C. A split view controller containing three toolbars
D. A navigation controller containing three tab bar controllers

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?

UITabBar in applications Medium
A. selectedItem
B. currentPage
C. selectionStyle
D. selectedIndex

37 Which configuration adds a visible title and system icon to a view controller displayed by a tab bar controller?

UITabBar in applications Medium
A. Assign a configured UINavigationBar to view
B. Assign a configured UITabBarItem to tabBarItem
C. Assign a configured UIBarButtonItem to navigationItem
D. Assign a configured UIToolbar to inputView

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?

Database using SQLite Medium
A. Append the email directly to the SQL string
B. Store the SQL command in a mutable string
C. Use a prepared statement with a bound parameter
D. Escape spaces before constructing the SQL string

39 Several related SQLite updates must either all succeed or all be undone. Which SQL commands should surround the updates?

Database using SQLite Medium
A. ATTACH DATABASE and DETACH DATABASE
B. SELECT and ORDER BY
C. CREATE TABLE and DROP TABLE
D. BEGIN TRANSACTION and COMMIT

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?

Database using SQLite Medium
A. SQLITE_ROW
B. SQLITE_BUSY
C. SQLITE_OK
D. SQLITE_DONE

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?

Using navigation controllers Hard
A. Observe UINavigationController.didShow notifications and compare the navigation stack afterward
B. Register the animation with the current transitionCoordinator and inspect the completion context
C. Implement navigationController(_:willShow:animated:) and use a fixed-duration property animator
D. Run the animation in viewWillDisappear(_:) and reverse it in viewDidAppear(_:)

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?

Using navigation controllers Hard
A. Create a new edge-pan recognizer that invokes popViewController(animated:) after the user's finger crosses half the screen, while disabling the original recognizer
B. Enable the gesture recognizer whenever viewDidAppear(_:) executes
C. Set the gesture recognizer's delegate to nil after the root controller appears
D. Avoid replacing the system gesture delegate and coordinate conflicts through gesture-recognizer APIs

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?

Using navigation controllers Hard
A. Assign [A, B, C] directly to the navigation controller's children property
B. Present B, present C, and dismiss X after the final presentation completes
C. setViewControllers([A, B, C], animated: false)
D. popToRootViewController(animated: false) followed by two pushes

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?

Concept of auto-layout Hard
A. Give the text field higher horizontal compression resistance than the label
B. Give the label higher horizontal compression resistance than the text field
C. Give both views required horizontal hugging and remove the stack's trailing constraint
D. Give the label lower horizontal content hugging than the text field

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?

Concept of auto-layout Hard
A. The content size remains zero until contentSize is assigned manually after Auto Layout finishes
B. Both horizontal and vertical scrolling occur because the guides are independent
C. Vertical scrolling works when the inferred content height exceeds the frame
D. Scrolling is disabled because the content view must have an explicit height

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?

Concept of auto-layout Hard
A. A bottom constraint is mandatory for every view using a fixed height
B. Both top and bottom constraints must be added to eliminate vertical ambiguity
C. A top constraint is mandatory even when height and vertical center are known
D. The vertical layout is determined, so the ambiguity must originate elsewhere

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?

Playing audio and video files Hard
A. Deactivate the audio session on .began and recreate the AVPlayer whenever .ended arrives
B. Ignore interruption notifications because AVPlayer automatically restores the user's exact playback intent
C. Record the prior playback state, pause on .began, and conditionally resume on .ended with .shouldResume
D. Pause on .began and always call play() on .ended, regardless of the prior state

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?

Playing audio and video files Hard
A. The replacement item must use a new AVPlayerLayer before end notifications can be posted
B. End notifications are emitted only once per AVPlayer instance, so a second player is required
C. The player's actionAtItemEnd automatically changed to .pause during item replacement
D. The observer was filtered to the old player item and was not registered for the replacement

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?

Playing audio and video files Hard
A. Use .ambient with .duckOthers, without enabling a background mode
B. Use .soloAmbient with .mixWithOthers, plus the Location background mode
C. Use .playback with .mixWithOthers, plus the Audio background mode
D. Use .record with .defaultToSpeaker, plus the Audio 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?

Implementing UICollectionView Hard
A. 5 items, but both index paths must refer exclusively to the original state
B. 5 items, with indices interpreted against the appropriate pre- and post-update states
C. 4 items because deletion validation occurs before insertion validation
D. 6 items because insertion validation occurs before deletion validation

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?

Implementing UICollectionView Hard
A. Give every represented item a stable, unique identifier in the snapshot
B. Reload the collection view before applying the duplicate identifiers
C. Use each item's current index path as its permanent identifier
D. Disable animated differences so duplicate identifiers are compared only by their visible cell contents and no longer conflict

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?

Implementing UICollectionView Hard
A. The label must have a required explicit height equal to its initial intrinsic height
B. The cell must override draw(_:) and update its frame from the text's bounding rectangle
C. The collection view must call sizeToFit() on every visible cell after each layout pass
D. Its content must have an unbroken vertical constraint chain from the content view's top to bottom

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?

UIToolbar Hard
A. A UIBarButtonItem created with the .fixedSpace system item
B. The trailing action because bar buttons automatically receive equal widths
C. The toolbar's first action because leading items have a higher resizing priority
D. A 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?

UIToolbar Hard
A. On each child controller through setToolbarItems(_:animated:)
B. Directly on navigationController?.toolbar?.items from the application delegate
C. On the navigation controller's root view through addSubview(_:)
D. In a second UIToolbar added over the navigation controller's built-in toolbar so each child can manage its own independent bar

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?

UITabBar in applications Hard
A. The More navigation controller's current top controller cast directly to the fifth child type
B. The selected tab bar item's screen-space horizontal coordinate
C. selectedViewController, compared with the controller's stable application identity
D. 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?

UITabBar in applications Hard
A. Create a new navigation controller every time didSelect is called
B. Create each tab's navigation controller once and retain it in the tab controller's viewControllers
C. Share one navigation controller and replace its root whenever the selected tab changes
D. Pop every navigation controller to root in 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?

UITabBar in applications Hard
A. Perform the pop only in tabBarController(_:didSelect:) after creating a replacement tab controller
B. Set selectedIndex to zero in viewDidDisappear(_:) of the current navigation controller
C. Remove and reinsert the selected navigation controller in the tab controller's viewControllers array
D. Detect reselection in tabBarController(_:shouldSelect:), pop the current stack, and return false

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?

Database using SQLite Hard
A. Begin a transaction, execute both updates, commit on success, and roll back on any failure
B. Write the debit, close the database, reopen it, and then write the credit
C. Execute both updates in autocommit mode and retry only the failed credit statement
D. Use two separate database connections so each account update can commit independently

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?

Database using SQLite Hard
A. Prepared statements cannot bind null values unless the column is declared NOT NULL
B. The database must first run VACUUM so null entries become visible to indexed comparisons
C. SQLite converts bound NULL to an empty string before evaluating equality
D. Comparisons with NULL are unknown; the query must use IS NULL for that case

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?

Database using SQLite Hard
A. Column text pointers may become invalid after stepping or resetting, so the bytes must be copied before then
B. Serialized mode guarantees statement safety but permanently disables text-column access from background queues
C. The pointer remains valid until the database closes, so the defect must be caused by the serial queue
D. Calling sqlite3_step automatically converts text storage to UTF-16 and invalidates only numeric columns