I’ve been learning Swift for a few months now and wrote my first function using generics today for a real world usecase.

Use case: merge two dictionaries, skipping duplicates. You’ve got to check for the same key types and value types.

extension Dictionary {
    func merge<K, V>(dict: [K: V]) -> [Key: Value]{
        var new: Dictionary<Key, Value> = [:]

        for (k, v) in self {
            new[k] = v
        }

        for (k, v) in dict {
            if let key = k as? Key {
                new[key] = v as? Value
            }
        }
        return new
    }
}

Swift - Child of the LLVM

Exploring what Swift achieves on LLVM that Obj-C could not. Continue reading

Understanding The LLVM - Introduction

Published on June 18, 2017

Developing for Hardware & Visibility

Published on May 24, 2017