2

I'm curious how I would use an if statement to see if a CGVector variable is nil, as objects are done like so:

if (!object){

    //Do This

}

But with CGVector it's not an object (As I know of). How would I determine if my CGVector variable is nil?

Mutch95
  • 271
  • 3
  • 14
  • 2
    `CGVector` is a `struct`. See there:http://stackoverflow.com/questions/2414809/default-value-of-an-objective-c-struct-and-how-to-test (for pointer explanation). Maybe you need to check: `if(yourVector.dx == 0 && yourVector.dy == 0)` instead. – Larme May 07 '14 at 10:54

1 Answers1

1

As you know it is a struct not an object

struct CGVector {
   CGFloat dx;
   CGFloat dy;
};
typedef struct CGVector CGVector;

Edit:

There is no such thing to check if a struct is nil.

Even if you check with dx==0 and dy==0, this is not correct at all an {0,0} is still a valid vector point.

For similar approach/question : How do I check if a CGPoint has been initialised?

Community
  • 1
  • 1
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140