Search code examples
objective-cnsstringnslog

NSLog NSString* print doesn't print


I am having problems with NSLog method and some objects. My objects return an NSString*, but the string is concatenated with several other strings like this :

-(NSString*) identiteSimple
{
    NSString *res = [[NSString alloc] initWithString:prenom];
    res = [res stringByAppendingString:@" "];
    res = [res stringByAppendingString:nom];
    return res;
}

however, when I try to print it using NSLog like this :

NSLog([myObj identiteSimple]);

Xcode warns me that:

"Format string is not a string literal (potentially insecure)"

And nothing gets printed. Does anyone have any idea why the NSString doesn't get printed?


Solution

  • Based on your comments to other answers, you're not actually allocating memory for your Personne object.

    Personne *moi = [moi initWithName:@"Lennon" prenom:@"John" civilite:@"Mr"];
    

    moi is nil when you try to call initWithName:prenom:civilite:. Messages to nil do nothing and return nil, so moi will still be nil, and identiteSimple will also return nil when you call NSLog().