How do I check if a CGPoint has been initialised?

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

    Since CGPointZero (0,0) and any other value you give a point may exist in your context you may want to initialize an NSValue with your point using:

    NSValue *pointVal = [NSValue valueWithCGPoint:point];
    

    You could do this based on some condition and then later test the NSValue for nil. NSValue can also be added to an array which would allow you to have an array of points should you need.

    To get the point later simply use:

    CGPoint point = [pointVal CGPointValue]; 
    

提交回复
热议问题