투케이2K

279. (TWOK/ERROR) [Ios] Fatal error: Unexpectedly found nil while unwrapping an Optional value 본문

투케이2K 에러관리

279. (TWOK/ERROR) [Ios] Fatal error: Unexpectedly found nil while unwrapping an Optional value

투케이2K 2024. 9. 14. 10:12
반응형

[환경 설정 및 설명]

프로그램 : Xcode

설 명 : [Ios] Fatal error: Unexpectedly found nil while unwrapping an Optional value

 

[에러 원인]

1. 데이터 변수 값 지정 시 Wrapping 된 형식으로 Optional 값은 변수로 설정할 수 없어 발생하는 이슈

2. unwrapping 수행 시 변수가 nil 값으로 되어 있는 경우 발생하는 이슈

 

[해결 방법]

1. 데이터 체크 방어 로직 강화

- 기본 변수 값 nil 체크

- if let Optional 타입 체크 및 unwrapping 수행 실시

- guard let 사용해 unwrapping 된 값이 특정 데이터 형식 인지 체크 수행


 

반응형
Comments