开发者社区 问答 正文

ios测试宏指令出错:“Expected identefier”

写了一个简单的测试宏指令,然后在下面代码中报错,不知道怎么修复?谢谢

#define test(condition) do{\
    if (condition)
    {\        //// <-----Expected identifier or (
        NSlog @"passed: " %@ #condtion); \

    }
    else
    {\
        NSLog(@"failed: " @ #condition); \

    }
}   //// <-----extraneous closing brace ( "}")

展开
收起
爵霸 2016-03-26 09:43:10 2275 分享 版权
1 条回答
写回答
取消 提交回答
  • 简单方法:
    #define test(condition) NSLog("%s: %s\n", condition ? "Passed" : "Failed", #condition);

    调用:

    int i = 6;
    test(i > 8);
    test(i < 8);

    输出:

    Failed: i > 8
    Passed: i < 8
    2019-07-17 19:15:22
    赞同 展开评论
问答分类:
问答地址: