This page is the latest incarnation of my official website. It’s a compendium of things I have published and other stuff I made during my spare time.

In this blog, I will keep track of the updates of this site. If you are interested, just subscribe to the RSS feed.

Pan y Queso equality in Swift
Sat, 20 Aug 2016 18:49:45 +0100
Structs in Swift are copied by value, while classes are copied by reference. If we want to check if the reference of an object is the same, we can use the triple equality operator. From Apple's book “The Swift Programming Language”,

Swift also provides two identity operators (=== and !==), which you use to test whether two object references both refer to the same object instance.

I've put here a few examples that you can copy-paste into a Playground to understand what the above means when using comparison operators:

struct Pan {
    let rating : Int
class Queso {
    let rating : Int
    init(rating: Int) {
        self.rating = rating
var q1 = Queso(rating: 0)
var q2 = Queso(rating: 0)
var q3 = q1 // same reference
var q4 = Queso(rating: 1)
q1 == q2 // error, == not defined
q1 === q2 // false
q3 === q1 // true
var p1 = Pan(rating: 0)
var p2 = Pan(rating: 0)
p1 == p2 // error, == not defined
p1 === p2 // error, they aren't references!
let quesos = [q1, q2]
quesos.contains(q1) // error, can't convert q1 to predicate
quesos.contains { $0 === q1 } // true
quesos.contains { $0 === q3 } // true
quesos.contains { $0 === q4 } // false

We can define an equality function if we want to check for the equality of the Pan and Queso values,

func ==(lhs: Pan, rhs: Pan) -> Bool {
    return lhs.rating == rhs.rating
p1 == p2 // true
func ==(lhs: Queso, rhs: Queso) -> Bool {
    return lhs.rating == rhs.rating
q1 == q2 // true
q1 == q4 // false
quesos.contains(q1) // still an error! pass a predicate

If we want to be able to pass a Queso to the "contains" or "indexOf" methods of array, we have to conform to the Equatable protocol. Having the equality function alone doesn't work. This will work,

class Queso : Equatable {
    let rating : Int
    init(rating: Int) {
        self.rating = rating
func ==(lhs: Queso, rhs: Queso) -> Bool {
    return lhs.rating == rhs.rating
// ...
quesos.contains(q1) // true

Happy coding!

Relevant StackOverflow questions:

My new game is out: Silabitas
Tue, 12 Jul 2016 09:02:37 +0100
It's a word puzzle game, similar to the Japanese game "mojipittan". The main rule is that you can't place a new piece unless you create a word with it. It works well in Japanese because they only have a few syllables, but I think in English it would be very difficult to achieve. In Spanish, we have more syllables, but less than English, so I think I managed to reach a good compromise by mixing syllables with single letters. So it's a bit like Mojipittan plus Scrabble.

The word is localized to several languages, although the puzzles are always in Spanish. If you play in a language other than Spanish, there's access within the app to Google Translate so you can check the meaning of the words you've discovered. There's also access to their definition in Spanish through RAE online.

Silabitas home page

EGSR 2016 notes
Mon, 27 Jun 2016 00:11:11 +0100
Some brief notes I took during the Eurographics Symposium on Rendering, last week in Dublin:

Swift Pixels: pixel art drawing app
Sat, 02 Apr 2016 11:02:54 +0100
I've spent last Easter finishing an app I had in mind. It's related to my previous post where I talked about Self-Organizing Maps. I used those maps to create the color palettes for the app, a simple pixel-art drawing app: Swift Pixels

The app is free. Enjoy

Self-Organizing Maps demo
Fri, 25 Mar 2016 23:02:35 +0000
I've recovered some old Matlab code and turned it into a Javascript demo to show how SOM neural networks work. I used them in my thesis years ago to generate color palettes based in universal categories.

Here's the demo and more details: Color Experiments

May and Yam Against Pollution
Sat, 19 Mar 2016 21:12:54 +0000
I released a game for iOS and AppleTV last week: May and Yam Against Pollution.

It's a "re-imagining" of a game I made 23 years ago for the Amiga 500. I tried to keep the retro style, so I recovered some of the original sprites, and also tried to mimic the "copper lines" from the Amiga

If you try it, please let me know what you think (Twitter: @endavid)

Javascriptifying EnDavid
Sun, 06 Mar 2016 09:22:04 +0000
I've refactored lots of this site so it's easier for me to maintain. Originally, I used a lot of static pages and PHP so people with old browsers could access it properly, but it was getting hard to maintain.

So I'm now making heavy use of Javascript. There are a few changes to make the page a little more dynamic, but otherwise it should look the same. I've only tested it on Chrome, Safari, and Safari for iOS. If you notice something is not working, please let me know.

Also, I've updated the list of works a bit.

Anyway, it's getting warmer, so let's go out and enjoy the spring!

Happy new year!
Fri, 01 Jan 2016 10:00:26 +0000
Happy New Year!
¡Feliz año nuevo 2016!


Previous year