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 store data in a local database
C. To manage a stack of view controllers
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. Deleting the view controller
B. Pausing the view controller
C. Pushing the view controller
D. Reloading 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 root view controller is deleted
C. The navigation bar is hidden
D. The application data is cleared

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

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

5 What is a major benefit of using Auto Layout?

Concept of auto-layout Easy
A. It adapts interfaces to different screen sizes
B. It converts videos into audio files
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 vertical spacing constraint
C. A horizontal spacing constraint
D. An aspect ratio 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. UITabBarController
C. AVAudioPlayer
D. UINavigationItem

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

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

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

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

10 What is the primary use of a UICollectionView?

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

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

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

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

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

13 What is the main purpose of a UIToolbar?

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

14 Which objects are commonly placed inside a UIToolbar?

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

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

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

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

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

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. An embedded relational database
B. A cloud-only graph database
C. A remote document 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. SELECT
B. INSERT
C. DELETE
D. UPDATE

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

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

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. Replace the navigation controller's root controller
B. Add the detail controller as a child controller
C. Push the detail controller with pushViewController(_:animated:)
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. setViewControllers([], animated:)
B. popToRootViewController(animated:)
C. dismiss(animated:completion:)
D. popViewController(animated:)

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

Using navigation controllers Medium
A. UINavigationController(nibName: "Home", bundle: nil)
B. UINavigationController(coder: homeController)
C. UINavigationController(navigationBarClass: nil, toolbarClass: nil)
D. 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?

Concept of auto-layout Medium
A. button.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20)
B. button.widthAnchor.constraint(equalToConstant: 20)
C. button.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
D. 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?

Concept of auto-layout Medium
A. Give the button a higher compression-resistance priority
B. Give the button a lower content-hugging priority
C. Give the label a lower content-hugging priority
D. Give the label a higher compression-resistance 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 clipsToBounds to true
B. Set autoresizesSubviews to false
C. Set translatesAutoresizingMaskIntoConstraints to false
D. Set 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?

Playing audio and video files Medium
A. AVPlayerViewController
B. AVAudioPlayer
C. AVCaptureSession
D. 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?

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

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

Playing audio and video files Medium
A. MPMediaPickerController with WKWebView
B. AVAudioPlayer with UIImageView
C. AVPlayer with AVPlayerViewController
D. 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?

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

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. Insert the model item, then call insertItems(at:)
C. Call setNeedsLayout(), then delete the old model item
D. Call reloadInputViews(), then insert the model item

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

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

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 custom plain bar button item
B. A flexible-space bar button item
C. A fixed-space bar button item
D. A system Done 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.subviews
B. toolbar.items
C. toolbar.constraints
D. toolbar.gestureRecognizers

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 navigation controller containing three tab bar controllers
B. A split view controller containing three toolbars
C. A tab bar controller containing three navigation controllers
D. A toolbar containing three navigation 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. selectedIndex
B. selectedItem
C. currentPage
D. selectionStyle

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 UITabBarItem to tabBarItem
B. Assign a configured UIBarButtonItem to navigationItem
C. Assign a configured UIToolbar to inputView
D. Assign a configured 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?

Database using SQLite Medium
A. Escape spaces before constructing the SQL string
B. Use a prepared statement with a bound parameter
C. Append the email directly to the SQL string
D. Store the SQL command in a mutable 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. BEGIN TRANSACTION and COMMIT
C. SELECT and ORDER BY
D. 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?

Database using SQLite Medium
A. SQLITE_BUSY
B. SQLITE_ROW
C. SQLITE_DONE
D. 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?

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. Run the animation in viewWillDisappear(_:) and reverse it in viewDidAppear(_:)
D. Implement 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?

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

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

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

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. Both horizontal and vertical scrolling occur because the guides are independent
B. Vertical scrolling works when the inferred content height exceeds the frame
C. Scrolling is disabled because the content view must have an explicit height
D. The content size remains zero until 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?

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. Record the prior playback state, pause on .began, and conditionally resume on .ended with .shouldResume
B. Deactivate the audio session on .began and recreate the AVPlayer whenever .ended arrives
C. Pause on .began and always call play() on .ended, regardless of the prior state
D. Ignore interruption notifications because 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?

Playing audio and video files Hard
A. The replacement item must use a new AVPlayerLayer before end notifications can be posted
B. The player's actionAtItemEnd automatically changed to .pause during item replacement
C. The observer was filtered to the old player item and was not registered for the replacement
D. End notifications are emitted only once per 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?

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

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

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. Use each item's current index path as its permanent identifier
B. Give every represented item a stable, unique identifier in the snapshot
C. Reload the collection view before applying the duplicate identifiers
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. Its content must have an unbroken vertical constraint chain from the content view's top to bottom
B. The collection view must call sizeToFit() on every visible cell after each layout pass
C. The label must have a required explicit height equal to its initial intrinsic height
D. The cell must override 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?

UIToolbar Hard
A. The trailing action because bar buttons automatically receive equal widths
B. The toolbar's first action because leading items have a higher resizing priority
C. A UIBarButtonItem created with the .fixedSpace system item
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. In a second UIToolbar added over the navigation controller's built-in toolbar so each child can manage its own independent bar
C. Directly on navigationController?.toolbar?.items from the application delegate
D. On the navigation controller's root view through 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?

UITabBar in applications Hard
A. selectedViewController, compared with the controller's stable application identity
B. selectedIndex, assumed to equal the visible position within the More table
C. The More navigation controller's current top controller cast directly to the fifth child type
D. The selected tab bar item's screen-space horizontal coordinate

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. Pop every navigation controller to root in viewWillDisappear(_:) to synchronize tab state
D. Share one navigation controller and replace its root whenever the selected tab changes

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. Detect reselection in tabBarController(_:shouldSelect:), pop the current stack, and return false
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. Perform the pop only in 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?

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

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. Comparisons with NULL are unknown; the query must use IS NULL for that case
B. SQLite converts bound NULL to an empty string before evaluating equality
C. The database must first run VACUUM so null entries become visible to indexed comparisons
D. Prepared statements cannot bind null values unless the column is declared 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?

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