iOS 버전 체크를 하는 올바른 코드
올바르지 못한 코드
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
}