Created
June 9, 2014 10:35
-
-
Save akisute/8892ff05c4294ddbb5b9 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
import Foundation | |
class GrayShark { | |
var name:String | |
var howSwim:String | |
init(name:String, howSwim:String) { | |
self.name = name | |
self.howSwim = howSwim; | |
} | |
} | |
func letSharkSwim(shark:GrayShark) -> String { | |
return "\(shark.name) swims like '\(shark.howSwim)'." | |
} | |
// OK, "The Average Shark swims like Swim Swim Swim Lurk" | |
letSharkSwim(GrayShark(name:"The Average Shark", howSwim:"Swim Swim Swim Lurk")) | |
// Error | |
// Could not find an overload for '__conversion' that accepts the supplied arguments | |
//letSharkSwim(nil) | |
// Custom Conversion Example | |
extension NilType { | |
@conversion func __conversion() -> (GrayShark) { | |
return GrayShark(name:"Gray Shark", howSwim:"UNBELIEVABLE POWERRRRRRRR") | |
} | |
} | |
// OK, "Gray Shark swims like UNBELIEVABLE POWERRRRRRRR" | |
letSharkSwim(nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment