I recently noticed this while working on an app- why is it that when you import a file you use
#import "SomeFile.h"
but when you are manipulating a string you use the @ symbol before the string, such as
NSLog(@"Hello World");
I know these two are not interchangeable, so is there a specific reason the #import directive doesn’t take a type of string? There must be some history/a good reason behind this. Maybe. Thanks for your time!
The
#importstatement is a preprocessor macro that is used when the compiler compiles your code. It makes sure that the file you are going to import is actually added to the source file you’re compiling.The compiler takes its own type of string to find the file. When not using the
"you are actually talking about aCtype string, orchar[].When using the
@""directive, you are actually talking about an object of typeNSString, which is in the end also, a 0-terminated array of chars.So basically, they’re both strings. But the
@""directive is used in Objective C to denote a string object, and the standard" "notation is used for lower level languages’ string types.