Skip to content

Instantly share code, notes, and snippets.

@klaaspieter
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klaaspieter/f81dea7642c661935dd5 to your computer and use it in GitHub Desktop.
Save klaaspieter/f81dea7642c661935dd5 to your computer and use it in GitHub Desktop.
let json = [{
name: "Klaas Pieter Annema",
age: 28
}, // Compiler infers Integer type for age
{
name: "Chris Eidhof",
age: "Unknown"
} // Compiler infers String type for age
];
struct Person {
// No types
var name
var age
init(untyped_dictionary) {
self.name = untyped_dictionary["name"]
self.age = untyped_dictionary["age"]
}
}
// Some magical parsing code
untyped_array = parse(json);
let person1 = new Person(untyped_array[0])
let person2 = new Person(untyped_array[1])
person1.age // type is Integer
person2.age // type is String? (question mark)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment