How to compare two CGSize variables?

Dvir Levy picture Dvir Levy · Jun 19, 2012 · Viewed 31.1k times · Source

I want to make sure a CGSize is smaller or equal to another CGSize. like:

CGSize firstSize = CGSizeMake(1.0,1.0);
CGSize secondSize = CGSizeMake(5.0,3.0);
if(firstSize <= secondSize){
    Do Stuff . . .
}

How would I compare this?

Answer

iOS-programmer picture iOS-programmer · Dec 5, 2012

To check for equality you can use, CGSizeEqualToSize function by Apple.

CGSize firstSize = CGSizeMake(1.0,1.0);
CGSize secondSize = CGSizeMake(5.0,3.0);

if(CGSizeEqualToSize(firstSize, secondSize)) {
    //they are equal
}else{
    //they aren't equal
}