티스토리 뷰

올바르지 못한 코드

 

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
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함