How to detect an Iphone X programmatically?

Swift and Objective-C developer tutorial on how to detect if an app is running on iPhone X
12 October 2017   12761

If you have an iOS app, now, with release of iPhone X you can face some new issues. In this tutorial, we will show you how to programmatically detect if an application is running on iPhone X.

Unfortunatelly, there is no direct methods on how to solve this issue. But let's use backdoor. Iphone X screen is 1125px X 2436px. So, we can use this information to solve this task.

Swift 3 and upper

if UIDevice().userInterfaceIdiom == .phone {
        switch UIScreen.main.nativeBounds.height {
        case 1136:
            print("iPhone 5 or 5S or 5C")
        case 1334:
            print("iPhone 6/6S/7/8")
        case 2208:
            print("iPhone 6+/6S+/7+/8+")
        case 2436:
            print("iPhone X")
        default:
            print("unknown")
        }
    }

Objective C

    if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone) {

        switch ((int)[[UIScreen mainScreen] nativeBounds].size.height) {

            case 1136:
                printf("iPhone 5 or 5S or 5C");
                break;
            case 1334:
                printf("iPhone 6/6S/7/8");
                break;
            case 2208:
                printf("iPhone 6+/6S+/7+/8+");
                break;
            case 2436:
                printf("iPhone X");
                break;
            default:
                printf("unknown");
        }
    }

or use screenSize.height as float 812.0f not int 812   

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    if (screenSize.height == 812.0f)
        NSLog(@"iPhone X");
}

Notice

DO NOT use the userInterfaceIdiom property to identify the device type, as the apple documentation explains,

For universal applications, you can use this property to tailor the behavior of your application for a specific type of device. For example, iPhone and iPad devices have different screen sizes, so you might want to create different views and controls based on the type of the current device.
 

Apple documentation

This property is just used to identify the running app's view style. However, the iPhone app (not the universal) could be installed in iPad device via App store, in that case, the userInterfaceIdiom will return the UIUserInterfaceIdiomPhone, too.

The right way is to get the machine name via uname.

TIOBE Index for July 2018 Released

Top programming lanuages for July 2018 index released: TypeScript continues to gain popularity 
09 July 2018   477

TypeScript entered the top 50 of the TIOBE index. A month earlier it appeared for the first time in the top 100 on line 93. TS is slowly catching up on the popularity of its competitor Dart from Google and behind it by 26 positions. TIOBE attribute this success to TypeScript with the popularity of the Angular framework, the latest versions of which are written in TS.

Objective-C returned to the top ten, Haskell - in the top 50. The scripting language Lua rose from 36 to 25 places. But F #, flew to the 36th line, losing 19 positions.

TIOBE July 2018 top 20
TIOBE July 2018 top 20

Since this month, two new programming languages have been added to the rating: Chapel and Pony. They took 97 and 173 places respectively.

TIOBE Index July 2018 Trends
TIOBE Index July 2018 Trends

The popularity of JavaScript is still high. All first half of 2018, the language spent in the top 10 and lost only 2 positions in February.

It is important to note that the rating does not show the "best" programming language, but only reflects the interest of IT industry representatives. The authors of TIOBE take into account the number of specialists around the world using a certain language, the number of language courses on educational resources, analyze the popularity of the AP with the help of the search engines of Google, Bing, Wikipedia, Amazon, YouTube, Baidu and others.