Skip to content

Instantly share code, notes, and snippets.

@coolnalu
Last active October 12, 2015 03:15
Show Gist options
  • Save coolnalu/e67c8f6e28654c4d0bce to your computer and use it in GitHub Desktop.
Save coolnalu/e67c8f6e28654c4d0bce to your computer and use it in GitHub Desktop.
//////////////////////////////////////////////////////////
//
// Chater 4 - Tim's Era
//
//////////////////////////////////////////////////////////
extension Company {
func isBiggerThan(company: Company) -> Bool {
if marketCapital == nil || company.marketCapital == nil {
print("Cannot compare market capital with a private company")
return false
}
// Comparing optionals
if marketCapital > company.marketCapital {
print("\(name) is bigger than \(company.name)")
return true
}
print("\(name) is not bigger than \(company.name)")
return false
}
}
apple.marketCapital = 624.4 // As of Oct 11, 2015
var google = Company(name: "Google", stock: "GOOG", capital: 450.7) // As of Oct 11, 2015
var dell = Company(name: "Dell")
apple.isBiggerThan(google) // true; "Apple Inc is bigger than Google"
apple.isBiggerThan(dell) // false; "Cannot compare market capital with a private company"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment