Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- func testAssert(x:Int)->Int {
- var res = 0
- if x > 0 {
- res += 3
- assertionFailure("testAssert")
- res += 5
- return res
- } else {
- res += 7
- }
- res += 2
- return res
- }
- let i:Int = Int(arc4random())
- print(i)
- let result = testAssert(i)
- print("\n")
- print(result)
- print("\n")
- print("End")
- // Result is:
- // 1661870581 -- (random result will vary but will be +ve
- // 9 -- (result of false case as assertion assumed valid in -Ounchecked in 6.4 or DISABLE_SAFETY_CHECKS in XC7
- // End -- Reaches end of execution
- // Program ended with exit code: 0 -- (Exits without error).
- // For -O /safety checks on builds the 9 is replaced by 8 showing the test remains in place.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement