I have a UIStepper with the following parameters:
value: 40
minimumValue: 35
maximumValue: 45
I want to update the UILabel (linked to it) at app' launch in order to make the it displays value. It's currently displaying the minimumValue by default and I don't know why. Any ideas ?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
GOAL: I'm currently unit testing the behavior of my UISwitch when it is pressed.
ISSUE: My issue I that the sendActions(for: .valueChanged) that I use to programmatically change the UISwitch's state is not working as I imagined. It doesn't make it change from false to true (in my example).
WHAT DID I DO ?: I'm using the following path:
I declared my UISwitch as true
I used sendActions(for: .valueChanged) for changing it to false
I finally used XCTAssertEqual() to check if it correctly equal to false as expected. (I also could have used XCTAssertFalse() to check directly if it was false.
Ps: I correctly passed loadViewIfNeeded() in my setUPWithError()
QUESTION: How can I test my UISwitch ?? Maybe using UI Tests ?
CODE: Here is my code:
var sut: ViewController!
override func setUpWithError() throws {
super.setUp()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
sut = storyboard.instantiateViewController(withIdentifier: "ViewController") as? ViewController
sut.loadViewIfNeeded()
}
func testGenderButton_ShouldUpdateValueWhenPressed() {
sut.genderSwitch.isOn = true
sut.genderSwitch.sendActions(for: .valueChanged)
XCTAssertEqual(sut.genderSwitch.isOn, false, "\(sut.genderSwitch.isOn) should be equal to false")
}
GOAL: I want to UI test my SegmentedControl - check that each segment is selected when tapped on it
CONTEXT: The shoeType UISegmentedControl has 3 segments [City, Running, Baskets]
CODE: Here is my code:
ViewController.swift :
@IBOutlet weak var shoeType: UISegmentedControl!
ViewControllerUITest.swift:
func testSegmentedControl_WhenTapped_ChangeSegment() {
app.launch()
let shoeTypeSegmentedControl = app.segmentedControls["city"]
app.segmentedControls["city"].tap()
XCTAssertEqual(shoeTypeSegmentedControl.label, "City")
}
Hi,
As I was reading the Apple book « Develop in Swift Fundamentals » I found out that:
a curly brace was not correctly indented on a code sample - page 184 (see screenshot n1)
a print statement result was not shown following an explanation - page 192 (screenshot n2)
Anyone knows on how to reach out to Apple in order to fix this ?
Thanks 👌🏻
Screenshot 1 :
Screenshot 2:
(https://books.apple.com/fr/book/develop-in-swift-fundamentals/id1581182804)