Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

How to Init a UIImage with a UIImage resulted from a call of a custom method?

Hi, I'm trying to define a custom method for resizing the images in my app. The custom method is defined in its own class, subclass of NSObject so that to use it for any image I have to manipulate in my (e.g.) UIViewControllers around the app. The parameters of the method are intended to be 1 UIImage (image to be resized) and 2 floats (width, height of the original image). The issue I have is that I am not sure how I can call the method during the Init of the UIImage that will contain the result of the method (i.e. resized image).

What I have tried:

  • call the custom method in the initialization of the UIImage, however I receive a syntax error.
  • rename the method into initWithData and change the result type of the method into a Data type. However, in this way it seems I won't be able to pass the width and height (or any additional parameter) of the resulting pictures.

Any help is greatly appreciated!