How do I check if a CGPoint has been initialised?

后端 未结 6 1822
你的背包
你的背包 2021-02-07 02:59

I would like to initially set a CGPoint property to a particular point (middle of screen). Other methods may subsequently wish to change this property. My thoughts were to initi

6条回答
  •  温柔的废话
    2021-02-07 03:35

    static CGPoint kInvalidPoint = {.x = NSIntegerMax, .y = NSIntegerMax};
    
    @implementation MyClass
    
    - init()
    {
        self = [super init];
        if (self) {
            _oldPoint = kInvalidPoint;
        }
        return self;
    }
    
    - (void)foo
    {
        if (CGPointEqualToPoint(self.oldPoint, kInvalidPoint)) {
            // Invalid point.
            return;
        }
    }
    
    @end
    

提交回复
热议问题