Removing Dependencies – ObjectMapper

Introduction


Hello developers, this blog post and the nexts to follow are blog posts series in order to help you unlock you code by removing all the dependencies created when you install a cocoapod. The solution is quite simple, remove the cocoapods and start writing your own code! Have a good look and thought about it,  it’s time to become an engineer!

Good Old Networking


NSURLConnection and NSJSONSerialization, seriously what else do you need ? I learned them and I made my own Networking Models which they work fantastic! I really prefer writing my own code and especially for the Networking Component, in contrast with the majority of the developers out there who use the well-known Cocoapods, Alamofire and ObjectMapper extensively. So this post will try to encourage the reader to start writing his own code and leave Cocoapods aside.

The Open-Source Community


I am in favour of the open-source Cocoapods community but why not write your own code, you are the developer after all. Isn’t it better not seeing a podfile, instead of seeing “Analysing 42 dependencies…” on which you don’t know on what your application is dependent on. When I started learning Swift I was lucky enough my friend Mike taught me the basics of Networking without the use of Cocoapods. Learning from the ground up helped me a lot to understand how the networking part works. But there are developers out there with a few years of iOS experience and they don’t know how to make a simple API request and map objects without the use of Cocoapods.

The Revenge of the Swift


This year is the time to create your own Networking Model and you will carry on working on it, it will be yours, it will freaking work until iOS 56 and you wont have to make pull requests in case you wish to add something new.

Swift 4 is willing to help you by introducing two new protocols, Decodable & Encodable so you don’t even have to use JSONSerialization, but with 1 line of code, maps your server data into your native object. Before saying “bye bye” to ObjectMapper, let’s remember how you can map JSON objects using ObjectMapper.

Model:

struct Temperature: Mappable {
    var celsius: Double?
    var fahrenheit: Double?

    init?(map: Map) {}

    mutating func mapping(map: Map) {
        celsius <- map["celsius"]
        fahrenheit <- map["fahrenheit"]
    }
}

Mapping:

let user = Mapper<User>().map(JSONString: JSONString)

Before saying something about this library I would like to see the Swift 4 way and lets sum them later on.

Model:

struct Temperature: Codable {
    var celsius: Double?
    var fahrenheit: Double?
}

Note that the variable name must be exactly as the Server Response name or you could use  a CodingKey to decode with your custom keys.

Mapping:

let decoder = JSONDecoder()
let object = try! decoder.decode(Book.self, from: response)

For sure the swift 4 way is much more simple and clean. Good job 👍🏽, now you are ready to cross out this ObjectMapper pod of your podfile.

In the next blog post I will make the same example this time with URLSession instead of using Alamofire.

 

Saboteur

The online blog/magazine Saboteur offered me to develop their application, simple user-interface, minimal design and great optimisation for mobile devices. The application I developed is a client application and I was responsible for both the client and server side design, development, and testing. You can download it here.

Saboteur’s pre-existing API was not implemented correctly (not mobile friendly) so I had to re-build it along with their database. I decided to spend some more time working on the api in order to make it “lighter” than before. I wanted the final application to send and receive the Network Requests extremely fast.

I started uploading every photo or media with the option “export for the web”. This option is a must-have in web design as all media have to be minimal in order to support mobile devices. After I cloned the rest of the pre-existing database and made all the end points. Finally the API is very “light” and the returning data are always small and can be downloaded very fast.

I developed this application using the native frameworks even for the network requests. The application starts with a main TableView and maps 5 recent posts. The user can scroll down and the application will ask for 5 more posts. A post TableViewCell has a background photo and a title. The user can touch each post and read its data and view the media natively in the next screen.

Color Sequence

Color Sequence is my third iOS game and it is already on the AppStore in just 1 month of developing. I really loved working on this app because I believe it has the prospects of becoming a really famous game. The point of this game is to improve your working memory by a quick and funny way. You can download and play here.

The game is simple, you have to tap all balls from the first you see until the last. Each time you win and a new ball will enter the game and you have start tapping all over from the first one. There are currently two game modes, Normal and Fast 10. Normal mode is just for scoring the highest score and fast 10 is the time you needed to score 10.

The app provides Game Center Leaderboards so you can challenge your friends and see who has the best working memory!

Capstone Project

This application is my capstone project for Information Technology – Digital Media Capstone course. The “Adventures of Samurai Kai” is a mobile game designed for iOS devices. I was responsible for the graphic design and developing of this application.

Game Information:

You control a character named “Kai” and you are a Samurai. You are trapped in a dark forest full of creatures and traps. Your mission is to travel to the other side of the forest, fast enough and collect all necessary recourses without falling in the traps and letting the dark mysterious creatures destroy you.

Documentation:

Full App Documentation

Instructors feedback 

You have exhibited a high level of professionalism and passion that really helped ignite innovation and creativity.

— Zeppos Galanos

Feel free to download it, run it from your favorite iOS device and let me know your thoughts! Download Link

Enjoy

Marathon Hero

Marathon Hero is my first iOS game which I am very proud of. I have been working for 1 year and 3 months for both the design prototypes, app design and final development. I have used Apple’s SpriteKit framework and developed it with Swift programming language just when it was first released. For this project I have designed the game, developed the game for iOS, and developed a backend API to store the user’s high-scores.

Marathon Hero is a Free and Ad-free game available for iOS devices.

Marathon Hero on the AppStore

Marathon Hero API on GitHub

Marathon Hero website

Ratings 

Well done works flawless nice idea too

Perfect game lots of fun and very nice graphics!!

Source: iTunes Customer Reviews 2015