Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:31:29+00:00 2026-06-13T22:31:29+00:00

Possible Duplicate: Which conditional compile to use to switch between Mac and iPhone specific

  • 0

Possible Duplicate:
Which conditional compile to use to switch between Mac and iPhone specific code?

I’ve defined a protocol which should work just fine on both Mac and iOS. However, one of the methods of the protocol would better return a specific class of object (rather than just ‘id’), but the class is not a foundation class and thus varies on the two platforms (for example, UIButton and NSButton).

How can I use a pragma mark like #ifdef TARGET_OS_IPHONE to include the same protocol header in two libraries, one built for iOS and one for Mac?

Here is my actual protocol and my (broken) attempt at conditional compilation

#import <Foundation/Foundation.h>

@protocol SharedAppDelegate <NSObject>

#ifdef TARGET_OS_IPHONE
@protocol UIApplicationDelegate;
+ (NSObject<UIApplicationDelegate> *)sharedAppDelegate;
#else
@protocol NSApplicationDelegate;
+ (NSObject<NSApplicationDelegate> *)sharedAppDelegate;
#endif

@end

One thing I know off the bat is that the target does not include the simulator, but I cannot find a solid example of one target which covers Mac and another all iOS incarnations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:31:30+00:00Added an answer on June 13, 2026 at 10:31 pm

    You’re gonna kick yourself. It’s #if not #ifdef. TARGET_OS_IPHONE is a #define that is set to 1 for iOS and 0 for mac. You want to use the simple #if.

    #if TARGET_OS_IPHONE
        NSLog(@"is iPhone or simulator");
    #else
        NSLog(@"is mac... probably");
    #endif
    

    Also, you can’t have a forward declaration of a protocol inside a protocol definition. You’ll have to do something like:

    #if TARGET_OS_IPHONE
    @protocol UIApplicationDelegate;
    #else
    @protocol NSApplicationDelegate;
    #endif
    
    
    @protocol SharedAppDelegate <NSObject>
    #if TARGET_OS_IPHONE
    + (NSObject<UIApplicationDelegate> *)sharedAppDelegate;
    #else
    + (NSObject<NSApplicationDelegate> *)sharedAppDelegate;
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Which exception should I raise on bad/illegal argument combinations in Python? I've
Possible Duplicate: What is the use of a partial class? In my code ,there
Possible Duplicate: Which keycode for escape key with jQuery This little piece of code
Possible Duplicate: Type result with conditional operator in C# Basically I have some code
Possible Duplicate: Why can't variables defined in a conditional be constructed with arguments? Consider
Possible Duplicate: Java: If vs. Switch For all the conditional statements that are observed
Possible Duplicate: Is glDisableClientState required? In OpenGL I've seen this code which follows this
Possible Duplicate: Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc I
Possible Duplicate: Which is more correct: <h1><a>..</a></h1> OR <a><h1>..</h1></a> Semantically, which is more correct:
Possible Duplicate: Which collection for storing unique strings? I am currently using a Dictionary<string,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.