iOS Swift - SwiftUI BasicsHow can you update a UIButton's title to "Pressed" immediately when it is tapped, using Swift code inside the action handler?Abutton.setTitle("Pressed", for: .normal)Bbutton.titleLabel?.text = "Pressed"Cbutton.setTitle("Pressed", for: .highlighted)Dbutton.currentTitle = "Pressed"Check Answer
Step-by-Step SolutionSolution:Step 1: Use setTitle(_:for:) methodThis method updates the button's title for a specific state.Step 2: Use .normal state to change the default titleSetting the title for .normal updates what is shown when button is not highlighted.Final Answer:button.setTitle("Pressed", for: .normal) -> Option AQuick Check:Correct method and state used to update title immediately [OK]Quick Trick: Use setTitle(_:for: .normal) to update button title [OK]Common Mistakes:Changing titleLabel?.text directly (won't update UI properly)Setting title for .highlighted state onlyTrying to assign to currentTitle property (read-only)
Master "SwiftUI Basics" in iOS Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepUITryChallengeBuildRecallPublish
More iOS Swift Quizzes Swift Language Essentials - Data types (Int, Double, String, Bool) - Quiz 14medium Swift Language Essentials - Enums with associated values - Quiz 2easy SwiftUI Basics - Spacer and padding - Quiz 7medium SwiftUI Layout - LazyVStack and LazyHStack - Quiz 4medium SwiftUI Layout - Overlay and background modifiers - Quiz 5medium SwiftUI Layout - Why layout controls visual structure - Quiz 5medium User Input and Forms - Toggle switch - Quiz 10hard User Input and Forms - Picker and DatePicker - Quiz 4medium iOS Basics and Setup - Xcode interface (navigator, editor, inspector) - Quiz 12easy iOS Basics and Setup - First iOS app - Quiz 14medium