If View A calls View B, which Swift Property Wrapper would you use in View B in order to return the value of a state to View A?
正解: C
解説: (JPNPDF メンバーにのみ表示されます)
問題 2
Select the location to set this app to run on an iPhone 14 in the simulator.
正解:
Explanation: This question belongs to Xcode Developer Tools , specifically the domain for building and running an app on the iOS simulator . In Xcode, the place where you choose whether the app runs on a simulator or a connected device is the run destination / scheme destination selector in the toolbar. This control appears near the top center of the Xcode window and displays the current destination, such as a simulator model or device target. To run the app on iPhone 14 , you click that selector and choose iPhone 14 from the available simulator list. Apple's Xcode documentation describes choosing a run destination before building and running the app in Simulator or on a device. So, for the hotspot, the correct place is the device/simulator dropdown in the top toolbar , not the preview canvas controls, not the project navigator, and not the code editor. That selector determines where the app launches when you press Run.
問題 3
Review the code snippet. What is the output from each print statement?
正解:
Answer the question by typing in the box. 10 Explanation: This question belongs to Swift Programming Language , specifically the domain covering structs, classes, properties, methods, and the difference between structures and classes . The key point is that Printer is declared as a class : class Printer { var copies: Int init(copies: Int) { self.copies = copies } } In Swift, classes are reference types . That means when you assign one class instance to another variable, both variables refer to the same object in memory rather than creating a separate copy. Apple's Swift language guide explains that classes are passed by reference, while structures are value types. So in this code: var printer1 = Printer(copies: 2) var printer2 = printer1 both printer1 and printer2 point to the same Printer instance. Next, this line changes the shared object: printer2.copies = 10 Because printer2 refers to the same instance as printer1, changing printer2.copies also changes printer1. copies. Therefore, when the code executes: print(printer1.copies) the output is 10 . This question tests one of the most important Swift concepts: classes are reference types , while structs are value types . If Printer had been a struct instead of a class, the result would have been different because assignment would copy the value rather than share the same instance.
問題 4
Review the code. You need to add the word " Great! " to the Capsule shape. Complete the code by typing in the boxes.
正解:
overlay, Text Explanation: This question belongs to View Building with SwiftUI , particularly the domain involving positioning and/or laying out a single SwiftUI view with standard views and modifiers . To place text on top of a shape such as a Capsule, SwiftUI uses the overlay modifier. Apple documents overlay as a view modifier that layers one view in front of another, which is exactly what is needed here: the text should appear on top of the blue capsule rather than beside or below it. The second blank must therefore be Text , because SwiftUI uses a Text view to display string content like " Great! " . The completed code is: struct ContentView: View { var body: some View { Capsule() .fill(.blue) .frame(width: 200.0, height: 100.0) .overlay( Text( " Great! " ) .font(.largeTitle) ) } } This works because Capsule() creates the shape, .fill(.blue) gives it the blue color, .frame(width:height:) sets its size, and .overlay(...) places the Text( " Great! " ) directly above that shape. This is a standard SwiftUI composition pattern: build a base view, then apply modifiers to style it and layer additional content. In App Development with Swift objectives, this aligns with understanding standard views, modifiers, and layout techniques in SwiftUI.
問題 5
In SwiftUI, how can you extract a subview from a main view to make the code more modular?