Search code examples
iosnsassert

Why does not this NSAssert with stringWithFormat compile?


stringWithFormat should return a string, why does this statement not compile

NSAssert(YES, [NSString stringWithFormat:@"%@",@"test if compiles"]);

when

NSAssert(YES, @"test if compiles");

compiles?


Solution

  • Use this as :

    NSAssert(YES, ([NSString stringWithFormat:@"%@",@"test if compiles"])); // Pass it in brackets ()
    

    Hope it helps you.