Reputation: 25
I have a define variable is a string like this
#define kyouTubeLink @"<iframe width='%d' height='%d' src='http://www.youtube.com/embed/%@?showinfo=0&modestbranding=1&rel=0&showsearch=0' frameborder='0' scrolling='0' allowfullscreen></iframe>";
so how to call this variable in another file.Thanks in advance
Upvotes: 0
Views: 42
Reputation: 726609
You cannot reference a variable that is #define
-d in another translation unit. You can put the definition in a header file, and #include
it from any translation unit that needs the definitions.
Since the definition is a C string literal, though, you would be better off defining a constant extern
variable for it, putting the declaration in a header, defining it in one of your translation units, and using everywhere else:
Common header (say, "YouTubeShared.h"):
extern const NSString* kyouTubeLink;
First translation unit (e.g. "AppDelegate.m" or whatever is a file that is better suited to hold the constant)
#include "YouTubeShared.h"
const NSString *kyouTubeLink = @"<iframe width='%d' height='%d' src='http://www.youtube.com/embed/%@?showinfo=0&modestbranding=1&rel=0&showsearch=0' frameborder='0' scrolling='0' allowfullscreen></iframe>";
... // More things go here
Second translation unit:
#include "YouTubeShared.h"
... // More things go here
NSString *res = [NSString stringWithFormat:kyouTubeLink, 123, 456];
Upvotes: 1