Yes! The Xcode compiler supports writing Objective-C inline with your C++ without any additional steps. As an example, here’s a snippet from a blueprint-callable function we wrote as a proof-of-concept for unlocking an achievement using Objective-C++:
void UMacOS::WriteAchievement(FString ID, float Percent)
{
#if PLATFORM_MAC
if (![[GKLocalPlayer localPlayer] isAuthenticated])
return;
NSString *nsID = [NSString stringWithUTF8String:TCHAR_TO_ANSI(*ID)]; // convert to NSString
GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:nsID];
achievement.percentComplete = Percent;
achievement.showsCompletionBanner = YES;
[GKAchievement reportAchievements:@[ achievement ]withCompletionHandler:^(NSError *error) {
if (error != nil)
{
// log error
}
}];
#else
// do nothing
#endif
}
I used #if PLATFORM_MAC preprocessor directives here so the compiler only tries to compile the mixed code on macOS, which prevents errors when building on windows. I’m sure there are cleaner ways to do this, but it was enough to prove to ourselves that gamekit integration works.
If you want do define an entire Obj-C class you can just add it in your file like normal. Some of the ios-specific code in the engine uses Objective-C++ if you want more examples.