2D Graphics programming under SWIFT

I wankt to write an app to display 2D graphics out of a file I have. What technique is better here ? Core graphics or metal ?

The immediate answer, since you mention 2d, would be not Metal. It’s probably too low level and mostly geared towards 3d.

However, the answer can also depend on several things: what are you doing with the graphics? A game, presentation, layout? There are many ways to display graphics on iOS and macOS using Swift. In order to choose the best tool for the job, start with some of the tutorials and get familiarized with them:

Hey Roberto, thanks for your answer. Well, I a newbie in Swift. I want to write an image viewer for weather satellite data. This is in 2D and the data is in a special binary format. For the moment this means simple 2D.

Welcome to Swift! I’m sure you will love it as much as all of us. Based on your response, sounds like Core Graphics would be the tool I’d use. The recipe would go something like this:

  1. Use CGBitmapContextCreate to create a raster canvas to draw your image on.
  2. Perform all drawing operations. Besides the usual primitives, you can do some cool stuff as well.
  3. When ready to display on the screen, convert to UIImage and push out: UIImage(CGImage: cgImage)

This topic was automatically closed after 166 days. New replies are no longer allowed.