NASA APOD

An iOS application leveraging NASA's APOD (Astronomy Picture of the Day) Open API. Built using Swift and Swift UI

NASA APOD

Introduction

While working on this I got to learn about Swift and it’s favorful syntax, It was seemed like gibberish to me at the beginning but I quickly got to like it over time; I’ll highlight below some of the things I found fascinating as I worked on this project.

API Calls In Swift

Just like learning any other language, one of the first things you’d want to do is to make your code do something with real world data. I have always been a huge NASA fan and I have built mini-projects with their Open API and this was another opportunity to explore another endpoint. This time it was the APOD (Astronomy Pictures of the Day). Coming from writing almost purely Typescript, there were syntax that were familiar to me and made it that much easier to pick up the language.

func getNASAPictures(completion: @escaping (Result<[PictureData], Error>) -> Void) -> Void  {
  let task = URLSession.shared.dataTask(with: URL(string: url)!, completionHandler: { data, response, error in
    if let error = error {
      completion(.failure(error as Error))
      return
    }
              
    do {
        let result = try JSONDecoder().decode([PictureData].self, from: data!)
        completion(.success(result))
    } catch let jsonError {
        completion(.failure(jsonError as Error))
    }
  })
        
  task.resume()
}

Work In Progress

This is still a work in progress and has been put on hold for now, but I look forward to when I get to continue working on it.