1

Is anyway to get a global C String const property in Objective-C?

I'm doing something like this:

const char *content_type = [@"application/vnd.ccm.pmsg.v1+json" UTF8String];

@implementation StringChannelCallable

...

@end

And I get this error:

Initializer element is not a compile-time constant

If I declare the content_type inside a method, this works, but I need to have it for global purpose to don't duplicate code

1 Answer 1

1

you can't use method in the variable or constant‘s declare

and you should use c language grammar to declare const char *, like this :

const char *content_type = "application/vnd.ccm.pmsg.v1+json";
Sign up to request clarification or add additional context in comments.

1 Comment

Both the pointer and the characters it points to should be const, like so: const char *const content_type = "application/vnd.ccm.pmsg.v1+json";.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.