This piece of code NSString * a = @"";
creates a new NSString. It is exactly the same as using [[NSString alloc] init]
.
If you want nil, you have to do like this NSString* a = nil
.
In Objective-C nil is used to create pointers to nothing, so don't use NULL of Nil. If you wan't more information about nil/Nil/NULL this article explains it all.
Edit for answering question in first comment:
NSString *fileName = nil;
NSLog(@"%@",[fileName isEqual:nil]?@"S":@"N");
NSLog(@"%@",[fileName isEqualTo:nil]?@"S":@"N");
NSLog(@"%@",[fileName isEqualToString:nil]?@"S":@"N");
In all of these cases your NSString is nil. In objective-C it is allowed to use methods on a nil object, but it wil always return a default value which is 0. 0 for a boolean type is NO. That is why you always get 'N'. It is a bit weird in this case because you're comparing nil to nil, but that's how it is. This post goes little bit more into detail
If you want to check if an object is nil do something like this:
if (filename) {
// Do something with filename
} else {
// filename is nil
}