Default value of an Objective-C struct and how to test

后端 未结 7 1097
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 15:33

I\'m trying to test if a property has been set yet. I know that with objects that I\'ve got:

CGRect ppGoalFrame;
LocalPlaySetup *localPlaySetup;
<
相关标签:
7条回答
  • 2021-01-31 16:16

    All instance variables in an Objective-C class are initialized to zero. So all pointers are nil, numbers are 0, and structs are zeroed. Since the CGRect is a plain struct, it will be initialised to origin.x=0, origin.y=0, size.width=0, size.height=0.

    So to test if your CGRect has been set, you need to compare it (by value) to zero. The CGRectIsEmpty function will do exactly this:

    if (CGRectIsEmpty(ppGoalFrame))
    {
        // ...
    }
    
    0 讨论(0)
提交回复
热议问题