Simple solution for interface issue

While developing this screen, which has a fixed button on the bottom as is standard throughout the app, I realised that the user might have a problem with the interface: the button is disabled by default, as it’s subject to agreeing with the terms of use — but the terms of use UISwitch, in this case, lies sneakily hidden under the button.

The user might then think that the app simply doesn’t work. Yikes!

After giving it some thought, I decided to change the button disabled behaviour for something that only seemed disabled but then could still listen to the tap gesture and react accordingly:

After setting the “fake disabled” implementation, now I check if the terms of use switch is checked and add an action to the button accordingly.

If the switch is off, it scrolls down to the TableFooterView in order to present the hidden switch. Otherwise it proceeds as expected.

The result is a simple and elegant animation presenting the entire footer.

Took me around 2 minutes to implement, but close to 10 minutes deciding about the approach.
Code often happens more inside the head than on the tip of the fingers.

Cheers!

My own code: How to treat JSON Deserialization objects and DB objects at the same time

So I’ve been using JSON Deserialization with the SwiftyJSON framework for my latest project, and it works like a charm. Thing is, this project is still very open for changes along the way, one of them being that the team is still not sure which information should be persisted in a Database. Because of this I was looking for a way to integrate ORMShark framework with SwiftyJSON in order to create persisted objects right after they are deserialized.

This is what I came up with:

1) The SwiftyJSONAccelerator Class

This class is easily created using CocoaPods’ pod 'SwiftyJSON' installed in the project and the JSONAccelerator app from their GitHub page.
The Application turns any valid JSON into an entire ready-to-use class, like the choice below:

The Class itself manages key-value data from JSON and creates an object from it. Great, huh?

But I still needed to work with Shark, and they have their own Type: SRKObject, and so I couldn’t possibly use the same Class for both of them.

2) The Shark helper Class

So I decided to create a new helper Class for the SRKObject and create a method that will take in an SwiftyJSON object as argument and pass its values to the SRKObject.

This is what the Class looks like:

3) Implementing the classes

Now whenever I need to persist an object after the request, I can just call the helper’s init() and update() methods and, voilá! It’s done!

And when I need to call the object back or get any of it’s properties, I just need to:

Hope you liked it and feel free to use my solution if you want!
See ya!

Teacher’s Challenge: Chasing A.I.

Teacher challenged us to create a basic A.I. that would guard a specific place and chase the player if he entered a specific area. If the player left the area of chase, the A.I. would go back to guarding position.

Program created using Python and Pygame.

Continue reading “Teacher’s Challenge: Chasing A.I.”