Convert OS X code to iOS

1

I'm trying to write OS X code to iOS Objective-C. I have code written for OS X and I want to use that code in iOS. I am not sure how to write the below code for iOS. I converted below code but I am getting warnings can only one please help me on this

OS X code

- (NSBitmapImageRep *) createImageRep:(NSSize)size
{
    // Create an image rep that we can use as the backing store for the canvas.
    //  To keep things simple we'll use a 32-bit RGBA bitmap image.
    int rowBytes = ((int)(ceil(size.width)) * 4 + 0x0000000F) & ~0x0000000F; // 16-byte aligned is good
    NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil 
                                                        pixelsWide:size.width 
                                                        pixelsHigh:size.height 
                                                     bitsPerSample:8 
                                                   samplesPerPixel:4 
                                                          hasAlpha:YES 
                                                          isPlanar:NO 
                                                    colorSpaceName:NSCalibratedRGBColorSpace 
                                                      bitmapFormat:NSAlphaNonpremultipliedBitmapFormat 
                                                       bytesPerRow:rowBytes 
                                                      bitsPerPixel:32];


    // Paint on a white background so the user has something to start with.
    NSGraphicsContext* imageContext = [NSGraphicsContext graphicsContextWithBitmapImageRep:imageRep];

    // "Focus" our image rep so the NSImage will use it to draw into
    [NSGraphicsContext saveGraphicsState];
    [NSGraphicsContext setCurrentContext:imageContext];

    [[NSColor whiteColor] set];
    [NSBezierPath fillRect: NSMakeRect(0, 0, size.width, size.height)];

    [NSGraphicsContext restoreGraphicsState];   

    return imageRep;
}

IOS code

- (CGImageRef) createImageRep:(CGSize)size
{


    int rowBytes = ((int)(ceil(size.width)) * 4 + 0x0000000F) & ~0x0000000F; // 16-byte aligned is good

    CGImageRef maskCreate = CGImageMaskCreate(CGImageGetWidth((mImageRep)),
                                              CGImageGetHeight((mImageRep)),
                                              CGImageGetBitsPerComponent((mImageRep)),
                                              CGImageGetBitsPerPixel((mImageRep)),
                                              CGImageGetBytesPerRow((mImageRep)),
                                              CGImageGetDataProvider((mImageRep)), NULL, false);




    // Create an image rep that we can use as the backing store for the canvas.
    //  To keep things simple we'll use a 32-bit RGBA bitmap image.



    // Paint on a white background so the user has something to start with.
    CGImageRef masked = CGImageCreateWithMask(maskCreate, maskCreate);

    CGImageRelease(maskCreate);

    UIImage *maskedImage = [UIImage imageWithCGImage:masked];
    UIGraphicsEndImageContext();
    [[UIColor whiteColor] set];
    [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, size.width, size.height)];


    return maskedImage.CGImage;
}

I am getting below warning.Please help me on this.

Warning message

ios
objective-c
macos
asked on Stack Overflow Jan 27, 2017 by Uttam • edited Jan 27, 2017 by shallowThought

1 Answer

1

The error states that the return type of your method conflicts with a previous declaration.

Your implementation in MyCLass.m is:

- (CGImageRef) createImageRep:(CGSize)size

You do have previously declaration with a different return type:

- (CGImageRef *) createImageRep:(CGSize)size ...

Probably you have added the * accidentally.

Check the MyCLass.h header file for this declaration:

- (CGImageRef *)createImageRep:(CGSize)size;

and remove the *:

- (CGImageRef)createImageRep:(CGSize)size;
answered on Stack Overflow Jan 27, 2017 by shallowThought • edited Jan 27, 2017 by shallowThought

User contributions licensed under CC BY-SA 3.0