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

后端 未结 7 1229
佛祖请我去吃肉
佛祖请我去吃肉 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 15:58

    Only pointers can be null. CGRect is a struct - it represents a contiguous block of memory. The only way to tell if it has been set it to check its contents.

    Apple does provide a constant CGRectNull. You could set your variable to this and use the CGRectIsNull function to determine if it has been set. CGRectNull is not the same as CGRectZero so you need not worry if the desired value is zero.

    Note that CGRectNull simply contains a CGRect struct filled with values that Apple can later identify for the CGRectIsNull function. It is not the same null as when comparing pointers.

提交回复
热议问题