REALstring → CFStringRef on iOS

I’m working on a cross-platform plugin (macOS, iOS) and still figuring out the SDK. I’ve hit a snag with trying to convert a REALString to a CFString/NSString: It doesn’t look like the REALstring → CFString conversion functions are supported for iOS targets?

#if TARGET_CARBON || TARGET_COCOA
CFStringRef REALCopyStringCFString( REALstring str ) {
…
}
#endif

Isn’t TARGET_CARBON true for iOS, so this should just work there?

Yes, in the iOS and macOS file, ConditionalMacros.h. But not in REALplugin.h:

Perhaps that’s where my problem is. I have an xcode setup with two targets and a packaging schema:

image

When the target is the macOS plugin, TARGET_CARBON and TARGET_COCOA resolve to the macOS ConditionalMacros.h file, but when the target is the iOS plugin, the TARGET_CARBON and TARGET_COCOA resolve to REALplugin.h, where these two flags are not set because the target is iOS. I will try to dig a little more and see why things aren’t resolving to the iOS ConditionalMacros.h file.

Did some more testing: TARGET_CARBON and TARGET_COCOA don’t resolve to the definitions in iOS SDK’s ConditionalMacros.h even in the sample XOJO SDK project with an iOS target: EyeControl (EyeControl_iOS_Simulator target—even after the project is updated with the correct SDK)

To summarize, There doesn’t seem to be a way to access the cocoa XOJO SDK functions in iOS plugin targets because REALplugin.h disables a lot of functionality if the plugin target is iOS.

Or maybe I’m reading this wrong? :man_shrugging:

I’m going to take another approach: I need to convert a REALstring to NSString, and I can do that with the cross-platform functions:

NSString * convertREALstringToNSString(REALstring rsString) {
	NSString *nsString = @"";

	size_t len = REALStringLength(rsString);
	uint32_t enc = REALGetStringEncoding(rsString);

	REALstringData data;
	bool v = REALGetStringData(rsString, enc, &data);
	if (v) {
		const unichar *c = (unichar *)data.data;
		NSStringEncoding nsEnc = NSUTF8StringEncoding;
		
		switch (enc) {
			// Note: Incomplete list of conversions
			case kREALTextEncodingUTF16LE: // Silicon and Intel
				nsEnc = NSUTF16LittleEndianStringEncoding;
				break;

			case kREALTextEncodingASCII:
				nsEnc = NSASCIIStringEncoding;
				break;
			
			default:
				break;
		}
		nsString = [[NSString alloc] initWithBytes:data.data length:len encoding:nsEnc];
	}
	
	return nsString;
}

I’m skipping some encodings, but does this seem like a reasonable approach?*

I’m hoping the answer is No and a better one is explained. :sweat_smile: Obviously, being able to use REALCopyStringCFString() on iOS is preferred.

For the time being, since that functionality does exist in our iOS framework, you should be able to just remove the #if TARGET_CARBON || TARGET_COCOA from there, and probably from rb_plugin.h as well. Or add an additional || TARGET_OS_IPHONE to that.

1 Like