Skip to content

Instantly share code, notes, and snippets.

@loganmoseley
Created October 24, 2016 01:16
Show Gist options
  • Save loganmoseley/4cf2bcf77cd4102a1ceba250ac4197c0 to your computer and use it in GitHub Desktop.
Save loganmoseley/4cf2bcf77cd4102a1ceba250ac4197c0 to your computer and use it in GitHub Desktop.
Demonstration of property name collision
// Person.swift
struct Person {
let givenName: String
let familyName: String
}
// SecretAgent.swift
protocol SecretAgent {
var givenName: String { get }
}
// Unrelated file
extension Person : SecretAgent {}
// Point of misunderstanding.
func doxxSecretAgent(agent: SecretAgent) {
print("Secret Agent's given name: \(agent.givenName)")
}
// Hope you didn't want that MI6 agent outed.
let regularPerson = Person(givenName: "Ian", familyName: "Fleming")
doxxSecretAgent(agent: regularPerson)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment