Last active
October 12, 2015 03:15
-
-
Save coolnalu/e67c8f6e28654c4d0bce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////// | |
// | |
// 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