UIImage convenience init in Swift cannot create resizable version

Originator:zacwest
Number:rdar://23128341 Date Originated:15-Oct-2015 10:04 AM
Status:Open Resolved:
Product:iOS SDK Product Version:
Classification:Other Bug Reproducible:Always
 
Summary:
I'm creating a convenience init method to generate resizable images, however it is not possible to do this in Swift.

For example, if my init method looks like:

init(…) {
  // …
  self.init(CGImage: someImage)
  //
  return self.resizableImageWithCapInsets(…)
}

This errors, because you cannot return non-nil. However, UIImage has no facility to adjust the cap insets in-place, because it's an immutable object.

Steps to Reproduce:
1. Attempt to create a convenience init method to generate resizable images
2. Fail because UIImage is not able to do so

Expected Results:
UIImage as an init method which can set the cap insets so I don't have to create another instance for it

Actual Results:
UIImage can only return a resizable image based on another image, which does not mesh well with Swift

Version:
Xcode 7.0.1

Notes:


Configuration:
N/A

Attachments:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!