Question

I updated my Xcode recently and am getting this warning. Can someone please help me fix it. Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int'

- (UIImage *)reflectedImageRepresentationWithHeight:(NSUInteger)height {

CGContextRef mainViewContentContext;
CGColorSpaceRef colorSpace;

colorSpace = CGColorSpaceCreateDeviceRGB();

// create a bitmap graphics context the size of the image
mainViewContentContext = CGBitmapContextCreate (NULL, self.bounds.size.width,height, 8,0, colorSpace, kCGImageAlphaPremultipliedLast);

// create a 2 bit CGImage containing a gradient that will be used for masking the 
// main view content to create the 'fade' of the reflection.  The CGImageCreateWithMask
// function will stretch the bitmap image as required, so we can create a 1 pixel wide gradient
    // WARING IS CAUSED BY LINE BELOW - height
CGImageRef gradientMaskImage = AEViewCreateGradientImage(1, height); // Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int'
Était-ce utile?

La solution

I don't know the function AEViewCreateGradientImage but I'll bet the second parameter takes an int instead of a NSUInteger. NSUInteger is typedefed to an unsigned long so that's why you get the warning. Pass an int instead of an NSUInteger and your warning will go away. You can probably pass an into to your method instead of an NSUInteger.

Edit

I took a look at Apples sample code and I'll expand on what your seeing. Basically it's because when the sample code was written an NSUInteger was likely typedefed to an unsigned int so they didn't get warnings. XCode 5.1 has moved forward and now it's typedefed to an unsigned long. I don't want to reinvent the wheel here and there are lots of stack overflow posts on this such as this one When to use NSInteger vs. int

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top