Where do you declare a constant in Objective-C?

后端 未结 4 1616
故里飘歌
故里飘歌 2020-12-07 18:54

I declared a constant in a header file const double EARTH_RADIUS=6353; that is imported to various other headers and I got a linker error.

L         


        
4条回答
  •  眼角桃花
    2020-12-07 19:30

    You can declare in the header, define it in a code file. Simply declare it as

    extern const double EARTH_RADIUS;
    

    then in a .m file somewhere (usually the .m for the .h you declared it in)

    const double EARTH_RADIUS = 6353;
    

提交回复
热议问题