
Using assert for debugging Swift 5.1
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.
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.
var userName = "Jim"
The program will hold on the assert And print the error message you have provided in the function.
Assertion failed: Wrong Username: file ULAssert.playground, line 5
