Which two statements about building an app are true? (Choose 2.)
You can preview a View in the Canvas without running your app.
Your phone must always be physically attached to your Mac to run your apps from Xcode on it.
You can run your app in the simulator with Generic iOS Device chosen.
You can run an app on your phone and get debug information in Xcode.
You need a paid Apple Developer account in order to run your app on your phone.
Comprehensive and Detailed Explanation From App Development with Swift domains:
This question belongs to Xcode Developer Tools , especially the objectives about using the Xcode interface, building and running an app, and debugging. A is true because Xcode supports SwiftUI previews in the canvas, allowing you to see a view’s interface directly in Xcode without fully launching the entire app in the normal run workflow. Apple’s documentation states that Xcode can display a preview of a custom SwiftUI view in the preview canvas and keep it updated as you make code changes.
D is also true because when you run an app from Xcode on a device, Xcode opens a debugging session in the debug area. Apple explicitly documents that after a successful build, Xcode runs the app and opens a debugging session, which means you can view debug information while the app is running on the phone.
The other options are false. B is false because a phone does not have to be physically attached at all times; modern Xcode workflows support device pairing and wireless development after setup. C is false because Generic iOS Device is not an actual simulator run target for launching the app like a specific simulator device. E is false because you do not need a paid Apple Developer Program membership merely to run an app on your own device for development; Apple provides support for development testing on devices with the required setup such as pairing and Developer Mode.
In SwiftUI, how can you extract a subview from a main view to make the code more modular?
Declare the subview as a variable inside the main view and call it directly.
Add the subview’s code directly into the main view’s body.
Create a new SwiftUI view struct and call it in the main view.
Use @State to manage subview content and use a binding to create a two-way connection.
Comprehensive and Detailed Explanation From App Development with Swift domains:
This question belongs to View Building with SwiftUI , specifically the objective about extracting subviews to simplify the structure of an overlarge view . The correct answer is C because the standard SwiftUI approach to modularizing a large interface is to create a separate custom view, usually as a new struct conforming to View, and then use that view inside the main view. Apple’s tutorials and documentation repeatedly show this pattern: move part of the UI into its own SwiftUI view type, then compose the main screen from smaller view components.
Option A is not the primary SwiftUI pattern for extracting a reusable subview. Option B does the opposite of modularization, because it keeps everything in the same large body. Option D is about state management and data flow, not about extracting a visual component into its own reusable subview. Apple’s SwiftUI materials emphasize composition, where views are lightweight and can be split into smaller reusable pieces for clarity, maintainability, and reuse. WWDC guidance also shows Xcode’s “Extract Subview” workflow, which creates a separate view structure from selected UI code.
Review the code.
var capitalCities = [ " USA " : " Washington D.C. " , " Spain " : " Madrid " , " Peru " : " Lima " ]
Which two statements add the capital city of " Italy " to the dictionary? (Choose 2.)
capitalCities[ " Rome " ] = " Italy "
capitalCities.append([ " Italy " : " Rome " ])
capitalCities[ " Italy " ] = " Rome "
capitalCities = capitalCities + [ " Italy " : " Rome " ]
capitalCities.updateValue( " Rome " , forKey: " Italy " )
Comprehensive and Detailed Explanation From App Development with Swift domains:
This question falls under Swift Programming Language , specifically the domain for managing data using collection types , with emphasis on dictionaries . In Swift, a dictionary stores data as key-value pairs , so in this example the country name is the key and the capital city is the value. To add a new entry, Swift supports two standard approaches. The first is subscript assignment , which is shown in option C : capitalCities[ " Italy " ] = " Rome " . Apple’s documentation explains that you can add a key-value pair to a dictionary by assigning a value for a new key through the dictionary subscript.
The second correct approach is option E : capitalCities.updateValue( " Rome " , forKey: " Italy " ). Apple documents that updateValue(_:forKey:) updates the value for an existing key, or adds a new key-value pair if the key does not already exist . That makes it equally valid for inserting " Italy " : " Rome " into the dictionary.
The incorrect options fail for different reasons. A reverses the key and value, making " Rome " the key and " Italy " the value. B is wrong because append is used with arrays, not dictionaries. D is not the standard valid insertion syntax for Swift dictionaries in this context; Swift’s documented mutation approaches here are subscript assignment and updateValue. Therefore, the two correct answers are C and E .
Which property wrapper allows you to read data from the system or device settings?
@State
@Environment
@Binding
@StateObject
Comprehensive and Detailed Explanation From App Development with Swift domains:
This question belongs to View Building with SwiftUI , specifically the objective about using property wrappers such as @State, @Binding, and @Environment to manage and share data between views.
The correct answer is @Environment because it is used to read values provided by the system or the surrounding view environment. These values can include device-related or system-provided information such as size classes, color scheme, locale, and dismiss actions. In SwiftUI, @Environment gives a view access to contextual information that it does not own directly, but which is supplied by the framework or ancestor views.
The other options are not correct for this purpose:
@State is used for local mutable state owned by the current view.
@Binding is used to create a two-way connection to state owned elsewhere, usually in a parent view.
@StateObject is used to create and own an observable reference-type object for the lifetime of the view.
So if you want a SwiftUI view to read data coming from system or device settings, the correct property wrapper is @Environment .
Review the code.

When entered into the TextField, which number will display a blue canvas on the SecondView?
3
2
4
1
This question belongs to View Building with SwiftUI , especially the domain on creating multiple views to implement app logic and sharing values between views. In FirstView, the value typed into the TextField is stored in number, which is a String. When the NavigationLink is tapped, the code passes Int(number) ?? 0 into SecondView. In Swift, converting a string to an integer with Int(...) uses an optional initializer, which means it returns an optional value and will produce nil if the string cannot be converted. The ?? 0 nil-coalescing operator then supplies 0 if conversion fails.
Inside SecondView, the body is:
Color(passedNumber == 3 ? .blue : .red)
This uses the ternary conditional operator. If passedNumber equals 3, the displayed color is blue; otherwise, it is red. Therefore, entering 3 into the TextField causes Int(number) to become 3, which makes the condition passedNumber == 3 true and displays a blue canvas. Any other listed number results in red.
So the correct answer is A. 3 . This matches the SwiftUI pattern of taking user input, converting it to the needed type, passing it into another view, and rendering UI conditionally based on that value.
Review the code snippet.

What value does the code output?
Answer the question by typing in the box.
2
This question belongs to Swift Programming Language , specifically the objectives covering functions , control flow , and default parameter values . The function is declared as func getAgeCategory(_ age: Int = 20) - > Int, which means if no argument is supplied, Swift uses the default value 20. Apple’s Swift documentation explains that you can define a default value for any parameter, and that value is used when the caller omits that argument. Since the code calls getAgeCategory() with no parameter, the function executes using age = 20.
The conditional logic is then evaluated in order:
if age > 64 → false, because 20 is not greater than 64
else if age > 19 → true, because 20 is greater than 19
so the function returns 2
Because Swift’s if / else if control flow stops at the first true condition, the later checks are never reached once age > 19 succeeds. Apple describes Swift as supporting standard control flow including conditional branching, and this example is a direct use of that branching behavior.
Therefore, print(getAgeCategory()) outputs 2 , which corresponds to option B .
Refer to this image to complete the code.

Note: You will receive partial credit for each correct answer


C:\Users\Waqas Shahid\Desktop\Mudassir\Untitled.jpg
This question belongs to View Building with SwiftUI , especially the objectives for using List views to iterate through collections and structuring views with standard SwiftUI containers. The screenshot shows two grouped sets of rows: one headed MY FRIENDS and one headed MY PETS . In SwiftUI, the correct container for a scrollable table-style presentation of rows is List, and the correct way to divide that list into labeled groups is Section. Apple documents List as a container that presents data in a single-column row-based layout, and Section as a way to organize list content into grouped areas with headers and optional footers. That is exactly the structure shown in the image. ( developer.apple.com , developer.apple.com )
The ForEach(names, id: \.self) and ForEach(pets, id: \.self) lines are already iterating through the arrays, so each ForEach should be wrapped inside a Section. The section labels such as " My Friends " and " My Pets " are provided with the header: label. So the intended code structure is:
List {
Section {
ForEach(names, id: \.self) { name in Text(name) }
} header: {
Text( " My Friends " )
}
Section {
ForEach(pets, id: \.self) { pet in Text(pet) }
} header: {
Text( " My Pets " )
}
}
This matches the UI shown in the image and aligns directly with SwiftUI list and section composition patterns in App Development with Swift.
Review the code snippet and then predict the output.

Total count: 11
Total count: 10
Total count: 20
Total count: 9
This question belongs to Swift Programming Language , especially the domains covering control flow , loops , logical operators , and guard . The loop runs through 0.. < max, and since max = 101, the values of num are 0 through 100. Inside the loop, the guard statement keeps only values that satisfy both conditions:
num % 5 == 0 → the number must be divisible by 5
num % 2 != 0 → the number must be odd
So the code counts numbers from 0 to 100 that are odd multiples of 5 . Those values are:
5, 15, 25, 35, 45, 55, 65, 75, 85, 95
That gives a total of 10 numbers. Therefore count becomes 10, and the printed output is:
Total count: 10
The key Swift concept here is that guard ... else { continue } skips any loop iteration that does not meet the required condition. Only matching values reach count += 1. This is a standard use of guard for early exit and of the remainder operator % for divisibility checks. Therefore, the correct answer is B .
What is the code snippet an example of?

Implicitly unwrapped optional
Optional chaining
Optional binding
Force unwrapping
This question belongs to Swift Programming Language , specifically the objective domain on Optional types and safe unwrapping . The snippet uses if let favoriteCol = favoriteColor { ... }, which is Swift’s standard syntax for optional binding . Apple’s documentation explains that optional binding is used to conditionally bind the wrapped value of an optional to a new constant or variable if the optional contains a value. That is exactly what this code does: if favoriteColor is not nil, its unwrapped String value is assigned to favoriteCol, and the code inside the if block runs.
This is not force unwrapping , because force unwrapping uses the ! operator, such as favoriteColor!. It is not optional chaining , because optional chaining uses ? to safely access properties, methods, or subscripts on an optional value. It is also not an implicitly unwrapped optional , which would be declared with String! rather than String?.
So the correct answer is C. Optional binding . This pattern is one of the most important safe-handling techniques in Swift because it lets you work with optional values only when they actually contain data, avoiding runtime errors and keeping control flow explicit.
TESTED 14 Jul 2026
