• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting iOS and Mac OS X when running unit tests
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting iOS and Mac OS X when running unit tests


  • Subject: Re: Detecting iOS and Mac OS X when running unit tests
  • From: Jens Alfke <email@hidden>
  • Date: Sun, 08 Apr 2012 13:25:27 -0700


On Apr 8, 2012, at 12:50 PM, Tito Ciuro wrote:

I'm not sure whether I should post this question on the Cocoa or Xcode list. I'll try here since it has to do with unit tests: when I'm running a unit test, I need to detect whether I'm running on the Mac or on the simulator. […]
At compile time I could use TARGET_IPHONE_SIMULATOR and TARGET_OS_MAC, but at runtime I'm not getting it right.

Why doesn't the compile-time check work? Any binary only runs on one of those three platforms, so there's nothing to check at runtime.

- (void)testFoo
{
    #if defined(TARGET_OS_IPHONE) && !defined(TARGET_OS_IPHONE_SIMULATOR)
        // Do something for iPhone...
    #else
        // Do something for Mac OS or simulator...
    #endif
}

(In my experience you can't use TARGET_OS_MAC because it's true in all three environments; I think this is defined for the benefit of code that also compiles on Windows?)

—Jens
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Detecting iOS and Mac OS X when running unit tests
      • From: Tito Ciuro <email@hidden>
References: 
 >Detecting iOS and Mac OS X when running unit tests (From: Tito Ciuro <email@hidden>)

  • Prev by Date: Re: Detecting iOS and Mac OS X when running unit tests
  • Next by Date: Re: Detecting iOS and Mac OS X when running unit tests
  • Previous by thread: Re: Detecting iOS and Mac OS X when running unit tests
  • Next by thread: Re: Detecting iOS and Mac OS X when running unit tests
  • Index(es):
    • Date
    • Thread