🍎 Apple/iOS

[iOS] assertionFailure, 배포버전에선 터지지 않도록 하기

PushedGun 2023. 10. 26. 23:09

1. 개요

fatalError를 사용하면, 개발 뿐 아니라 배포버전에서도 Error가 난다.

그런데 개발 시에는 Error를 내고 싶지만, 배포할 땐 내지 않도록 하고 싶은 경우가 있을 것이다.

2. assertionFailure

이런 경우에 사용하기 좋다.

단, fatalError처럼 return을 무시해주진 못하니 구현을 해두어야 한다는 번거로움이 있다.

 

https://developer.apple.com/documentation/swift/assertionfailure(_:file:line:)

 

assertionFailure(_:file:line:) | Apple Developer Documentation

Indicates that an internal sanity check failed.

developer.apple.com