How do I check if a CGPoint has been initialised?

后端 未结 6 1829
你的背包
你的背包 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:16

    Create two CGPoint properties, that way they are both "uninitialized". Set one of them and use the second one to check whether or not they are equal.

    @interface ClassName ()
    
    @property (nonatomic) CGPoint point1;
    @property (nonatomic) CGPoint point2;
    
    @end
    
    @implementation ClassName
    
    self.point1 = CGPointMake(69.0f, 180.0f);  //arbitrary numbers
    
      //if not equal, then if statement proceeds
    if (!CGPointEqualToPoint(self.point1, self.point2) {
        //your code here
    }
    
    @end
    

    Idk if you'd consider this way hackish though. And I know your question was already answered, but I had kinda the same dilemma till I thought of this.

提交回复
热议问题