Personally I don’t use a assert much but you can use it to make sure the value you are getting from a variable is the correct one.
1 2 3 |
var userName = "Bill" assert(userName == "Bill", "Wrong Username") |
The above code does not have an error so the program will continue but if we change the user name.
1 |
var userName = "Jim" |
The program will hold on the assert And print the error message you have provided in the function.
1 2 |
Assertion failed: Wrong Username: file ULAssert.playground, line 5 |