1

I am creating a UIImage object in swift by passing image data to it. Similar to how its done in objective-c

UIImage imageWithData

However, i see error that says: imageWithData is not available for swift.

What is the alternative for imageWithData for Swift ?

Nick
  • 183
  • 1
  • 3
  • 6
  • What's the exact code you're using? – Lyndsey Scott Mar 25 '15 at 18:42
  • 1
    The methods `initWithX` become an initializer with a parameter of `x`. Thus, `initWithData:...` becomes`UIImage(data:...)`. – Rob Mar 25 '15 at 18:44
  • 1
    Did you read the complete error message? My Xcode displays `error: 'imageWithData' is unavailable: use object construction 'UIImage(data:)'` – Martin R Mar 25 '15 at 18:48

1 Answers1

8

I can't find the imageWithData class method in the UIImage documentation, however you could use init(data:) data method:

let image:UIImage = UIImage(data:youDataHere);
Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76