Re: Creating mixed target iOS and Mac project
Re: Creating mixed target iOS and Mac project
- Subject: Re: Creating mixed target iOS and Mac project
- From: Christiaan Hofman <email@hidden>
- Date: Thu, 2 Sep 2010 13:58:42 +0200
On Aug 24, 2010, at 13:51, Jason Swain wrote:
> I have been using a combined iPhone and Mac project for quite some time now. In general I prefer to have separate files for each target rather than using macros. So I'd have two main.m files in this case. I just used the auto generated ones from existing projects. Because they have the same name they need to be in different folders. You'd do the same for info.plist.
>
> I also set up a config.h file to locate as many of the platform dependencies in one place. I've got a few classes that do simple things with images and in config.h I #define IMAGE_CLASS to be either NSImage or UIImage and this lets me reuse the same code on both platforms. The classes are not exactly the same so this only works so far, it's probably most useful where you are passing these objects around rather than manipulating them. You could do the same with NSColor/UIColor too probably.
>
>
> Jason
>
In fact they don't need to have the same name, the only thing that matters is that the /function/ is always called main(). So you can simply rename one or both of the main.m files, and just add the appropriate one to the compile phase of each target.
Christiaan
> On 24 Aug 2010, at 12:39, Ralf Schuchardt wrote:
>
>>
>> Am 24.08.2010 um 12:20 schrieb Antonio Nunes:
>>
>>> On 24 Aug 2010, at 10:48, Antonio Nunes wrote:
>>>
>>>> I suppose I need to add some preprocessor directives to main.m to setup the right environment:
>>>>
>>>> #ifdef BUILD_FOR_IOS
>>>> int retval = UIApplicationMain....;
>>>> #elifdef BUILD_FOR_MAC
>>>> int retval = NSApplicationMain....;
>>>> #endif
>>>>
>>>> Is this the right way to do it, or is there a better way? In addition, the build settings pane does not show the reprocessing section. How do I add the definitions to the build settings?
>>>
>>> Actually, that code is not totally correct, and an older message on this list suggests a better definition to use. Better would be (showing all of main's contents):
>>>
>>> #ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
>>> NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
>>> int retVal = UIApplicationMain(argc, argv, nil, nil);
>>> [pool release];
>>> return retVal;
>>> #else
>>> return NSApplicationMain(argc, (const char **)argv);
>>> #endif
>>>
>>> But: it looks like the Architectures and Base SDK settings at the Project level trumps the same settings at the Target level. Shouldn't this be the other way around? (Using Xcode 3.2.3 here.) How do I get Xcode to use the correct Architecture and Base SDK, depending on the active target?
>>
>> That seems to be a bug in this Xcode version. You can select the right active SDK by Option-clicking on the "Overview" popup before building.
>>
>> Ralf
>>
>> _______________________________________________
>> 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
>
> _______________________________________________
> 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
_______________________________________________
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