An interesting phenomenon (an apple bug or pit?), a precompiled macro that distinguishes between a real machine and a simulator

Source: Internet
Author: User

Target_iphone_simulator and Target_os_iphone are Apple's two macro definitions,

Located in Ios->usr/include/targetconditionals.h in the real-machine SDK,

In the emulator SDK in simulator->usr/include/targetconditionals.h

(The version of Xcode I'm using at this time is 5.1,SDK version 7.1)


Look closely at the definitions in its simulator SDK:

#define Target_os_iphone 1
#define Target_iphone_simulator 1


Then look at the definition in the real-machine SDK:


#define Target_os_iphone 1
#define Target_iphone_simulator 0


It can be found that the difference between the two is only the value of target_iphone_simulator , and Target_os_iphone is the same, is true.


So, when we distinguish the real-time simulator, we must use target_iphone_simulator to judge, the use of Target_os_iphone will not be effective.

The logic of this and the normal person should be conflict (anyway I think so, Khan)

So when you use it, be careful not to get a hole in the apple!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.