# 2D Graphics programming under SWIFT

**URL:** <https://forums.kodeco.com/t/2d-graphics-programming-under-swift/79150>\
**Category:** Swift\
**Created:** [August 15, 2019, 7:11pm UTC](https://forums.kodeco.com/t/2d-graphics-programming-under-swift/79150 "2019-08-15T19:11:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/mmim/32/81494_2.png) [@mmim](https://forums.kodeco.com/u/mmim)\
**Post date:** [August 15, 2019, 7:11pm UTC](https://forums.kodeco.com/t/2d-graphics-programming-under-swift/79150/1 "2019-08-15T19:11:48Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![robertomachorro](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robertomachorro/32/111603_2.png) [@robertomachorro](https://forums.kodeco.com/u/robertomachorro)\
**Post date:** [August 16, 2019, 2:37pm UTC](https://forums.kodeco.com/t/2d-graphics-programming-under-swift/79150/2 "2019-08-16T14:37:07Z")

</div>

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:

- [Metal Tutorial: Getting Started](https://www.raywenderlich.com/7475-metal-tutorial-getting-started)
- [Core Graphics Tutorial: Lines, Rectangles, and Gradients](https://www.raywenderlich.com/475829-core-graphics-tutorial-lines-rectangles-and-gradients)
- [How To Create A Simple 2D iPhone Game with OpenGL ES 2.0 and GLKit – Part 1](https://www.raywenderlich.com/2956-how-to-create-a-simple-2d-iphone-game-with-opengl-es-2-0-and-glkit-part-1)
- [2D Apple Games by Tutorials Updated for Swift 3 and iOS 10](https://www.raywenderlich.com/914-2d-apple-games-by-tutorials-updated-for-swift-3-and-ios-10)
- [2D Skeletal Animation with Spine Tutorial](https://www.raywenderlich.com/2589-2d-skeletal-animation-with-spine-tutorial)

---

<div class="post-metadata">

**Author:** ![mmim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/mmim/32/81494_2.png) [@mmim](https://forums.kodeco.com/u/mmim)\
**Post date:** [August 16, 2019, 5:16pm UTC](https://forums.kodeco.com/t/2d-graphics-programming-under-swift/79150/3 "2019-08-16T17:16:22Z")

</div>

> [@robertomachorro](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![robertomachorro](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robertomachorro/32/111603_2.png) [@robertomachorro](https://forums.kodeco.com/u/robertomachorro)\
**Post date:** [August 16, 2019, 8:43pm UTC](https://forums.kodeco.com/t/2d-graphics-programming-under-swift/79150/4 "2019-08-16T20:43:27Z")

</div>

Welcome to _Swift_! I’m sure you will love it as much as all of us. Based on your response, sounds like [Core Graphics](https://developer.apple.com/documentation/coregraphics) would be the tool I’d use. The recipe would go something like this:

1. Use [CGBitmapContextCreate](https://developer.apple.com/documentation/coregraphics/1455939-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](https://www.raywenderlich.com/2335-image-processing-in-ios-part-1-raw-bitmap-modification).
3. When ready to display on the screen, convert to [UIImage](https://developer.apple.com/documentation/uikit/uiimage) and push out: UIImage(CGImage: cgImage)

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [January 29, 2020, 11:11am UTC](https://forums.kodeco.com/t/2d-graphics-programming-under-swift/79150/5 "2020-01-29T11:11:51Z")

</div>

Closed on January 29, 2020, 11:11am UTC

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