0

Swift provides a special preprocessor directive called os to check what operating system you are running:

struct A {
#if os(iOS)
    let a: AvailableOnIOS
#elseif os(tvOS)
    let a: AvailableOnTVOS
#endif
}

I am interested if there is something similar in Objective-C that can be used like

@interface A: NSObject
#if os(iOS)
@property (nonatomic, strong) AvailableOnIOS* a;
#elseif os(tvOS)
@property (nonatomic, strong) AvailableOnTVOS* a;
#endif
@end
Roman Podymov
  • 4,168
  • 4
  • 30
  • 57
  • Like this https://stackoverflow.com/questions/3181321/which-conditional-compile-to-use-to-switch-between-mac-and-iphone-specific-code ? – Martin R Dec 16 '19 at 15:50
  • 2
    @MartinR Yes, thank you. Should I use `#if TARGET_OS_IPHONE` instead of `#if os(iOS)` in Objective-C? – Roman Podymov Dec 16 '19 at 16:07
  • 1
    To be clear: You want to build an app that works on iOS and TV OS devices, and want a compiler directive that generates the correct code for each target? – Duncan C Dec 16 '19 at 17:55
  • The other thing we need to do sometimes is check code at runtime to see what device we are running on. It sounds like you instead want to compile different code for each platform? – Duncan C Dec 16 '19 at 17:55
  • @DuncanC I want a compiler directive that generates the correct code for each target, something like `os(iOS)` in Swift. – Roman Podymov Dec 16 '19 at 18:12
  • 1
    Yeah, you should look at the link Martin provided. Yes, in Objective-C you want something like `#if TARGET_OS_IPHONE` – Duncan C Dec 16 '19 at 18:18

0 Answers0