This product is not supported for your selected Datadog site. ().
이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다. 현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.
Metadata
ID:swift-code-style/forced-unwrapped
Language: Swift
Severity: Notice
Category: Code Style
Description
Declaring a variable as optional clearly signals that it may not hold a valid value and could be nil. Force-unwrapping bypasses that safety and will cause a runtime crash if the value is actually nil. Even if you check for nil first, relying on force-unwrapping is still discouraged because it undermines the intent of optionals. A safer and more maintainable approach is to use optional binding or optional chaining to handle values gracefully.
Non-Compliant Code Examples
vargreeting:String?// ...println(\(greeting!))// Noncompliant; could cause a runtime errorifgreeting!=nil{println(\(greeting!))// Noncompliant; better but still not great}