In Xcode go into the Scheme for Testing (top of screen) or Option Command U. On the Test pane the Info tab has a check box for the Debugger. Uncheck it and testing will not spin-up a Debug Executable which will save lots of time while running test. And if you are doing TDD - you never use the old Debugger anyway. - right!
Here's my autocomplete code snippet for writing a unitTest. I like that it contains working example code in the Given/When/Then format.
func test_<#MethodName#>_<#Scenario#>() throws {
// a really great explaination for future you
// Given conditions
var someValue = false
// When some action occurs
if !someValue { someValue.toggle() }
// Then test this
XCTAssertTrue( someValue )
}
I sometimes forget the format of a simple TDD test - so I have a code complete snippet for an example. This one uses the classic - Given/When/Then pattern.
Boy - this was hard to figure out. But I found it buried in a StackExchange post...
I have a SwiftUI Toggle button on my App's Setting page. It controls the printing of an Arabic numeral-style equation on the History page of the App.
At the App launch, it is Off. But after the app has run through a few UI Tests - it could be in any state. Tests need a reliable state to function appropriately.
One of the secrets is to use firstMatch on the Toggle - I think this means the switch is a child of the Label and we expect there is only ONE child (hence firstMatch):
base10Toggle.switches.firstMatch.tap()
Then I used the practice of returning the toggle to OFF after the test. To ensure the next test will find the state consistant.
Figuring out how to create your own autocomplete code snippets in Xcode is tough. The snippet browser doesn't have a button (like it should). I have to google it each time.
The menu item is in the last place you will look: Editor > Create Code Snippet...
Then you will want to know how to encode placeholder text. That secret is with <# placeholder text #>.
Good luck.
It is 2022 and we are starting to see articles about using SwiftUI's natural pattern instead of MVVM or MVC. Wondering about this natural pattern? It was detailed in some of the WWDC talks in 2019 I think... go look...
Apple didn't give it a snappy name - so it didn't seem to stick in people's memory.
The slides show... User interaction and the Action->State->View loop. Then there is this code screen showing how the Environment holds state for the App.
If you allow it - SwiftUI - will handle the data dependencies for you. So, don't work against the framework by imposing another on top of the natural Swifty view model.
See: Data Flow Through SwiftUI - WWDC19
Wondering how to see the visualization of the Build Timeline? Well first go to the Reports Navigator. Select a Build Log. Then in the Adjust Editor Options menu select Assistant editor (top right).
Do you know what those Building | 63 / 105 numbers mean? 105 what?
I had hoped that the Timeline would give me a clue... I'm guessing build tasks. But I cannot find a reference to that in the Xcode docs.