StaticString with Obj-C const or define

Wondering why this doesn't compile:

// in Objective-C:

extern NSString * const TEST_STATIC_OBJC_STRING_CONSTANT;

NSString * const TEST_STATIC_OBJC_STRING_CONSTANT = @"test";

// In Swift:

let ss = StaticString(stringLiteral: TEST_STATIC_OBJC_STRING_CONSTANT)
// Error: Cannot convert value of type 'String' to expected argument type 'StaticString'

and

// in Objective-C:

#define TEST_STATIC_OBJC_STRING_DEFINE @"test"

// in Swift:

let ss = StaticString(stringLiteral: TEST_STATIC_OBJC_STRING_DEFINE)
// Error: Cannot convert value of type 'String' to expected argument type 'StaticString'

Seems like both consts and defines from Objc headers should satisfy as a string literal, no?

StaticString is compiled with a direct pointer to the memory in question, which an NSString doesn't provide. (It can provide it at runtime, but not compile time.)

Terms of Service

Privacy Policy

Cookie Policy