티스토리 뷰
올바르지 못한 코드
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { // Load resources for iOS 7 or later } else { // Load resources for iOS 6.1 or earlier } |
사유
1: Version numbers aren’t always a simple floating-point number, for example “4.2.1” is a valid iOS version number.
2: You’re doing raw floating point comparison. Due to the finite precision of floating point numbers, your comparison may fail (or succeed) when you wouldn’t otherwise expect it to. – Mac
좋은 코드
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
// Load resources for iOS 6.1 or earlier
}
else
{
// Load resources for iOS 7 or later
}
f ([우리가쓸패키지 isIOS7OrHigher])
{
// Load resources for iOS 7 or later
}
else
{
// Load resources for iOS 6.1 or lower
}
'macOS, iOS' 카테고리의 다른 글
Xcode 단축키들 (0) | 2019.07.05 |
---|---|
[Swift] Closure - $0, escaping, autoclosure (0) | 2019.07.05 |
swift의 고차 함수 (0) | 2019.07.04 |
Functional Programming을 처음 본다면 (0) | 2019.07.04 |
Nil Coalescing Operator(Nil 병합 연산자) ?? (0) | 2019.07.04 |