美文网首页iOS开发错误集锦
Objective-C: Expected ']'

Objective-C: Expected ']'

作者: slowdony | 来源:发表于2018-04-19 15:54 被阅读12次

    定义一个宏
    #define FontCustomName(name,size) ([UIFont fontWithName:name size:size])

    看上去这个宏没什么问题,但是你在用的时候就出现问题了,
    FontCustomName(@"PingFangSC-Regular",15)

    会报错,错误信息.Expected ']'

    然后你就会很费解,这没毛病呀,为什么会报错呢,
    查找相关资料发现,你定义的宏里的参数的size和方法里的size重名了,这样就导致错误

    原因当你使用这个宏FontCustomName(@"PingFangSC-Regular",15)其实就等价于[UIFont fontWithName:name 15:15]

    这明显错误呀

    修改宏参数
    ``#define FontCustomName(name,fontSize) ([UIFont fontWithName:name size:fontSize])`
    编译通过

    相关文章

      网友评论

        本文标题:Objective-C: Expected ']'

        本文链接:https://www.haomeiwen.com/subject/eyvwkftx.html