Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
Can anyone help me with this please.

Code:
-(UIImage*)resizedImageWithBounds:(CGSize)bounds
{
    CGFloat horizontalRatio = bounds.width / self.size.width;
    CGFloat verticalRatio = bounds.height / self.size.height;
    CGFloat ratio = MIN(horizontalRatio, verticalRatio);
    CGSize newSize = CGSizeMake(self.size.width * ratio, self.size.height * ratio);
    
    UIGraphicsBeginImageContextWithOptions(newSize, YES, 0);
    [self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return newImage;
}
What does MIN() do?
 
Last edited:

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,544
6,042
I tried using it in my app and it wasn't recognized, so it doesn't seem to be part of a standard library/framework.

It appears to be a macro, based on the decision to name it in all capitals. (I'll be honest, Xcode suggested it to me. I already suspected it was a macro, but it didn't even occur to me that there might be a naming convention... I've always just used whatever names I feel like for macros.)

If I had to guess, I'd say that somewhere in a header you import (or possibly you import a header that imports it... or possibly so on) you'll probably find something like

Code:
#define MIN(A,B) (A<B)?A:B

That's just a guess though. The macro I just typed would replace every instance of MIN(A,B) with a ternary operator that first checks if A is less than B, and if it is, return A, and if it isn't, return B. In effect, it returns the lesser of A and B, or finds the MINimum (my guess for what MIN is short for) value of A and B.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
MIN and MAX are a part of standard Objective-C. A quick check shows that they are macros defined in NSObjeCRuntime.h, which is almost certainly #imported in every .m file.

MIN returns the minimum value of the two parameters and MAX returns the maximum value of the two parameters.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.